Data format conversion method and device and computer readable storage medium
By establishing a shared field position mapping table, the format conversion of domestic freight rule text data is solved, and the problem that changes in freight data format affect the effective time of freight data is ensured that the freight search system is compatible with data of different formats.
Patent Information
- Application Number
- CN202411910415.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-23
- Publication Date
- 2025-04-18
AI Technical Summary
Changes in the text data format of domestic freight rules have caused the freight publishing system to push full data, which seriously affects the effective time of freight data. The domestic ticket freight search system needs to be compatible with new and old formats.
By establishing a common field position mapping table, the data format conversion is realized by mapping the relative position of the common field in the first data format template and its relative position in the second data format template.
The format conversion of domestic freight rule text data is realized, and the field length is supported during the data format change process, ensuring that the freight search system is compatible with data of different formats, and avoiding format changes affecting the effective time of freight data.
Smart Images

Figure CN119847985A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of data processing technology, and in particular to a data format conversion method, device and computer-readable storage medium. Background Art
[0002] At present, the domestic fare rule text data is regularly released every 15 minutes through the fare publishing system. When the domestic passenger ticket fare search system processes the domestic fare rule text data, it first saves the domestic fare rule text data pushed by the fare publishing system to the local data processing server, and then the data processing service processes the domestic fare rule text data into data that can be used by the domestic passenger ticket fare search system.
[0003] After the format of the domestic fare rule text data was changed, the version of the fare publishing system was changed accordingly, which resulted in the fare publishing system taking several hours to push the full amount of domestic fare rule text data, seriously affecting the effective time of the fare data. Therefore, in order to avoid the impact of the format change of the domestic fare rule text data on the effective time of the fare data, the domestic passenger ticket fare search system needs to be compatible with the new and old formats of the domestic fare rule text data. Summary of the invention
[0004] The present invention aims to provide a data format conversion method, device and computer-readable storage medium, which realize the format conversion of domestic freight rate rule text data by establishing a common field position mapping table.
[0005] To achieve the above object, the present invention provides the following technical solutions:
[0006] A data format conversion method, comprising:
[0007] Establishing a common field position mapping table, and writing a mapping relationship between a relative position of the common field in the first data format template and its relative position in the second data format template into the common field position mapping table;
[0008] Based on the common field position mapping table, the text data in the first data format is converted into the text data in the second data format.
[0009] Furthermore, the establishing of the common field position mapping table, writing the mapping relationship between the relative position of the common field in the first data format template and the relative position of the common field in the second data format template into the common field position mapping table, includes:
[0010] Obtaining a first data format template, reading the length of the first data format template and field information of each field, including the field name, field length, and the relative starting position and relative ending position of the field in the first data format template;
[0011] Obtain the second data format template, read the length of the second data format template and field information of each field, including the field name, field length, and the relative starting position and relative ending position of the field in the second data format template;
[0012] Find common fields, where the common fields are fields with the same field names in the first data format template and the second data format template;
[0013] Establishing a mapping relationship between a relative position of the common field in the first data format template and its relative position in the second data format template according to the field length of the common field in the first data format template and its field length in the second data format template;
[0014] According to the field reading order, the mapping relationship of the common fields is written into the common field position mapping table.
[0015] Further, the establishing a mapping relationship between the relative position of the common field in the first data format template and its relative position in the second data format template according to the field length of the common field in the first data format template and its field length in the second data format template includes:
[0016] If the field length of the common field in the first data format template is smaller than the field length of the common field in the second data format template, then establishing a first position mapping relationship of the common field;
[0017] If the field length of the common field in the first data format template is greater than the field length of the common field in the second data format template, then establishing a second position mapping relationship of the common field;
[0018] If the field length of the common field in the first data format template is equal to the field length of the common field in the second data format template, a third position mapping relationship of the common field is established.
[0019] Furthermore, the common field first position mapping relationship includes:
[0020] The field name of the common field;
[0021] The first copy starting position is the relative starting position of the common field in the first data format template -1;
[0022] The first copy end position is the relative end position of the common field in the first data format template - 1;
[0023] The first pasting start position is the relative start position of the common field in the second data format template -1;
[0024] The first pasting end position is the relative end position of the common field in the second data format template - 1 - (the field length of the common field in the second data format template - the field length of the common field in the first data format template).
[0025] Furthermore, the common field second position mapping relationship includes:
[0026] The field name of the common field;
[0027] The second copy starting position is the relative starting position of the common field in the first data format template -1;
[0028] The second copy end position is the relative end position of the common field in the first data format template - 1 - (the field length of the common field in the first data format template - the field length of the common field in the second data format template);
[0029] The second pasting starting position is the relative starting position of the common field in the second data format template -1;
[0030] The second pasting end position is the relative end position of the common field in the second data format template - 1.
[0031] Furthermore, the third position mapping relationship of the common field includes:
[0032] The field name of the common field;
[0033] The third copy starting position is the relative starting position of the common field in the first data format template -1;
[0034] The third copy end position is the relative end position of the common field in the first data format template -1;
[0035] The third pasting start position is the relative start position of the common field in the second data format template -1;
[0036] The third pasting end position is the relative end position of the common field in the second data format template - 1.
[0037] Further, the converting of the text data in the first data format into the text data in the second data format based on the common field position mapping table includes:
[0038] Reading text data in a first data format;
[0039] Traversing the common field position mapping table, and reading mapping relationships in a write order, wherein the mapping relationship is one of a common field first position mapping relationship, a common field second position mapping relationship, and a common field third position mapping relationship;
[0040] Extracting a specified field from the text data in the first data format according to the read mapping relationship, and writing the specified field into a specified position in the buffer area;
[0041] After the traversal is completed, the data in the buffer area is stored as text data in the second data format.
[0042] Further, if the first position mapping relationship of the common field is read, the first designated field is extracted from the text data in the first data format, wherein the byte corresponding to the first copy start position is extracted from the text data in the first data format as the first byte of the first designated field, and the byte corresponding to the first copy end position is extracted as the last byte of the first designated field;
[0043] The extracted first designated field is written into a buffer area, wherein the first byte of the first designated field is pasted to the corresponding first paste start position, and the last byte of the first designated field is pasted to the corresponding first paste end position.
[0044] Furthermore, it also includes:
[0045] If the second position mapping relationship of the common field is read, the second designated field is extracted from the text data in the first data format, wherein the byte corresponding to the second copy start position is extracted from the text data in the first data format as the first byte of the second designated field, and the byte corresponding to the second copy end position is extracted as the last byte of the second designated field;
[0046] The extracted second designated field is written into a buffer area, wherein the first byte of the second designated field is pasted to the corresponding second paste start position, and the last byte of the second designated field is pasted to the corresponding second paste end position.
[0047] Furthermore, it also includes:
[0048] If the third position mapping relationship of the common field is read, the third designated field is extracted from the text data in the first data format, wherein the byte corresponding to the third copy start position is extracted from the text data in the first data format as the first byte of the third designated field, and the byte corresponding to the third copy end position is extracted as the last byte of the third designated field;
[0049] The extracted third designated field is written into a buffer area, wherein the first byte of the third designated field is pasted to a corresponding third paste start position, and the last byte of the third designated field is pasted to a corresponding third paste end position.
[0050] Furthermore, the length of the buffer area is the same as the length of the text data in the second data format.
[0051] Further, after storing the data in the buffer area as text data in the second data format, the method further includes:
[0052] Clear the buffer area.
[0053] Based on the same inventive concept, the present invention also provides an electronic device, comprising: a memory and a processor; the processor is used to read and execute a computer program stored in the memory to implement the aforementioned data format conversion method.
[0054] Based on the same inventive concept, the present invention also provides a computer storage medium, in which computer executable instructions are stored, and the computer executable instructions can implement the above-mentioned data format conversion method when executed.
[0055] Technical effects and advantages of the present invention:
[0056] (1) Establishing a common field position mapping table, realizing data format conversion through the mapping relationship between the relative positions of common fields in different data format template data, which is applicable to text data in various data formats;
[0057] (2) Support operations such as adding fields and changing field length during data format changes;
[0058] (3) This method is used to convert the format of domestic freight rate rule text data, so that the domestic freight rate search system is compatible with domestic freight rate rule text data in different data formats, thereby preventing the effective time of the freight rate data from being affected by the format change of the domestic freight rate rule text data.
[0059] Other features and advantages of the present invention will be described in the following description, and partly become apparent from the description, or understood by practicing the present invention. The purpose and other advantages of the present invention can be realized and obtained by the structures pointed out in the description, claims and drawings. BRIEF DESCRIPTION OF THE DRAWINGS
[0060] In order to more clearly illustrate the technical solutions in the embodiments of the present invention, the following briefly introduces the drawings required for use in the description of the embodiments. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without creative work.
[0061] Figure 1 Schematic diagram of a data format conversion method according to an embodiment of the present invention;
[0062] Figure 2 4 is a processing flow chart of a data format conversion method in an embodiment of the present invention. DETAILED DESCRIPTION
[0063] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0064] In order to achieve the purpose of making the domestic freight rate search system compatible with domestic freight rate rule text data in different data formats, the present invention discloses a data format conversion method, such as Figure 1 As shown, the method includes:
[0065] Step S1, establishing a common field position mapping table, and writing a mapping relationship between a relative position of a common field in a first data format template and a relative position of a common field in a second data format template into the common field position mapping table;
[0066] The first data format template is data in the first data format used as a reference template. The second data format template is data in the second data format used as a reference template. The common fields are fields with the same field name in the first data format template and the second data format template.
[0067] The common field position mapping table stores the position mapping relationship between the relative positions of the common fields in two different data format template data.
[0068] Step S2: based on the common field position mapping table, convert the text data in the first data format into the text data in the second data format.
[0069] In the embodiment of the present invention, by establishing a common field position mapping table and utilizing the mapping relationship between the relative positions of common fields in template data of different data formats, format conversion is performed on text data of various data formats.
[0070] According to this embodiment, the establishment of the common field position mapping table, writing the position mapping relationship between the relative position of the common field in the first data format template and its relative position in the second data format template into the common field position mapping table, includes:
[0071] Obtaining a first data format template, reading the length of the first data format template and field information of each field, including the field name, field length, and the relative starting position and relative ending position of the field in the first data format template;
[0072] Obtain the second data format template, read the length of the second data format template and field information of each field, including the field name, field length, and the relative starting position and relative ending position of the field in the second data format template;
[0073] Find common fields, where the common fields are fields with the same field names in the first data format template and the second data format template;
[0074] Establishing a mapping relationship between a relative position of the common field in the first data format template and its relative position in the second data format template according to the field length of the common field in the first data format template and its field length in the second data format template;
[0075] According to the field reading order, the mapping relationship of the common fields is written into the common field position mapping table.
[0076] The data template (first / second data format template) generally includes multiple fields. The field information of each field is read from the data template in sequence and stored in a field information array, wherein the field information includes the field name, field length, and the relative starting position and relative ending position of the field in the data template. Field length = relative ending position - relative starting position + 1. The sum of the field lengths of all fields is the length of the data template. The field information arrays of the first data format template and the second data format template are traversed to find whether there are common fields with the same field name. For any common field, its field length in the first data format template is compared with its field length in the second data format template, and a mapping relationship between the relative position of the common field in the first data format template and its relative position in the second data format template is established. The position mapping relationship can be understood as a mapping of the position relationship generated when the common field is migrated from the first data format template to the second data format template.
[0077] According to a preferred embodiment of the present invention, if the field length of the common field in the first data format template is smaller than the field length of the common field in the second data format template, a first position mapping relationship of the common field is established.
[0078] The common field first position mapping relationship includes:
[0079] The field name of the common field; the first copy starting position is the relative starting position of the common field in the first data format template - 1; the first copy ending position is the relative ending position of the common field in the first data format template - 1; the first paste starting position is the relative starting position of the common field in the second data format template - 1; the first paste ending position is the relative ending position of the common field in the second data format template - 1 - (the field length of the common field in the second data format template - the field length of the common field in the first data format template).
[0080] According to another preferred embodiment of the present invention, if the field length of the common field in the first data format template is greater than the field length of the common field in the second data format template, a common field second position mapping relationship is established.
[0081] The shared field second position mapping relationship includes:
[0082] The field name of the common field; the second copy starting position is the relative starting position of the common field in the first data format template - 1; the second copy ending position is the relative ending position of the common field in the first data format template - 1 - (the field length of the common field in the first data format template - the field length of the common field in the second data format template); the second paste starting position is the relative starting position of the common field in the second data format template - 1; the second paste ending position is the relative ending position of the common field in the second data format template - 1.
[0083] According to another preferred embodiment of the present invention, if the field length of the common field in the first data format template is equal to the field length of the common field in the second data format template, a third position mapping relationship of the common field is established.
[0084] The third position mapping relationship of the common field includes:
[0085] The field name of the common field; the third copy starting position is the relative starting position of the common field in the first data format template - 1; the third copy ending position is the relative ending position of the common field in the first data format template - 1; the third paste starting position is the relative starting position of the common field in the second data format template - 1; the third paste ending position is the relative ending position of the common field in the second data format template - 1.
[0086] Furthermore, the mapping relationship is written into a common field position mapping table according to the field reading order, and the text data in the first data format is converted into text data in the second data format based on the common field position mapping table.
[0087] Here are the steps:
[0088] Reading text data in a first data format; the text data may be any piece of text data in the first data format;
[0089] Creating a buffer area, wherein the length of the buffer area is the same as the length of the text data in the second data format;
[0090] Traversing the common field position mapping table, and reading mapping relationships in a write order, wherein the mapping relationship is one of a common field first position mapping relationship, a common field second position mapping relationship, and a common field third position mapping relationship;
[0091] Extracting a specified field from the text data according to the read mapping relationship, and writing the specified field into a specified position in the buffer area;
[0092] After the traversal is completed, the data in the buffer area is stored as text data in the second data format.
[0093] In this embodiment, according to the writing order of the mapping relationship, if the first position mapping relationship of the common field is read, the first designated field is extracted from the text data in the first data format, wherein the byte corresponding to the first copy starting position is extracted from the text data in the first data format as the first byte of the first designated field, and the byte corresponding to the first copy ending position is extracted as the last byte of the first designated field; then the extracted first designated field is written into the cache area, specifically, the first byte of the first designated field is pasted to the corresponding first paste starting position, and the last byte of the first designated field is pasted to the corresponding first paste ending position.
[0094] If the second position mapping relationship of the common field is read, the second designated field is extracted from the text data in the first data format, wherein the byte corresponding to the second copy starting position is extracted from the text data in the first data format as the first byte of the second designated field, and the byte corresponding to the second copy ending position is extracted as the last byte of the second designated field; then the extracted second designated field is written into the cache area, specifically, the first byte of the second designated field is pasted to the corresponding second paste starting position, and the last byte of the second designated field is pasted to the corresponding second paste ending position.
[0095] If the third position mapping relationship of the common field is read, the third designated field is extracted from the text data in the first data format, wherein the byte corresponding to the third copy starting position is extracted from the text data in the first data format as the first byte of the third designated field, and the byte corresponding to the third copy ending position is extracted as the last byte of the third designated field; then the extracted third designated field is written into the cache area, specifically, the first byte of the third designated field is pasted to the corresponding third paste starting position, and the last byte of the third designated field is pasted to the corresponding third paste ending position.
[0096] Furthermore, after the data in the buffer area is stored as text data in the second data format, the buffer area is cleared so as to perform format conversion on the next text data in the first data format.
[0097] The data conversion method provided by the implementation of the present invention is applicable to text data in any data format. Moreover, since the method realizes data format conversion by utilizing the mapping relationship of the relative positions of common fields in different data format templates, it supports operations such as adding fields and changing field lengths during the data format change process, thereby expanding the scope of application.
[0098] After the domestic freight rate rule text data is converted into a data format using the method, the domestic freight rate search system is compatible with the domestic freight rate rule text data in both the new and old formats, and the freight rate publishing system and the domestic freight rate search system can decouple the format change of the domestic freight rate rule text data, thereby preventing the effective time of the freight rate data from being affected by the format change of the domestic freight rate rule text data.
[0099] The following is a detailed description through a specific embodiment.
[0100] like Figure 2 As shown, a data format conversion process is provided, which is specifically applied to converting the format of domestic freight rate rule text data.
[0101] Process 1: Parse the data template and create a common field location mapping table
[0102] In this embodiment, an Excel document is used as the storage medium of the template file. The data template recorded in the template file is actually the text data of the domestic freight rate rules. The Excel document operation uses the code library provided by the system.
[0103] a. Open the old data format template file, obtain the old data format template from the file, read the data length (OldLength) of the old data format template, and read the field information of each field in the template in turn, and store the field information of each field in the old data format template into the array OldFieldInfos;
[0104] A data template generally stores multiple fields. Each field in the template is traversed to read the field information. The structure of the field information is shown in Table 1.
[0105]
[0106] Table 1
[0107] For example, the field information of the field m_prefixId is shown in Table 2, which can be abbreviated as (m_prefixId, 1, 3, 3).
[0108]
[0109] Table 2
[0110] The data length of the old data format template is 65 bytes, including 6 fields. The old data format template is parsed and the information of each field is saved in the array OldFieldInfos, as shown in Table 3:
[0111] Field Name Starting position End position Field length m_prefixId 1 3 3 m_actionCode 4 4 1 m_cxrCode 5 11 7 m_locationCode 12 18 7 m_ruleId 19 32 14 m_applicationId 33 65 33
[0112] Table 3
[0113] According to Table 3, the field information of each field in the array OldFieldInfos is abbreviated as follows:
[0114] (m_prefixId,1,3,3); (m_actionCode,4,4,1); (m_cxrCode,5,11,7);
[0115] (m_locationCode,12,18,7); (m_applicationId,33,65,33);
[0116] (m_ruleId,19,32,14);
[0117] b. Open the new data format template file, obtain the new data format template from the file, read the data length (NewLength) of the new data format template, and read the field information of each field in the template in turn, and store the field information of each field in the old data format template into the array NewFieldInfos;
[0118] The data length of the new data format template is 73 bytes, including 6 fields. The new data format template is parsed and the information of each field is saved in the array NewFieldInfos, as shown in Table 4:
[0119]
[0120]
[0121] Table 4
[0122] According to Table 4, the field information of each field in the array NewFieldInfos is as follows:
[0123] (m_prefixId,1,3,3); (m_actionCode,4,4,1); (m_cxrCode,5,17,13);
[0124] (m_locationCode,18,24,7); (m_applicationId,41,73,33);
[0125] (m_ruleId,25,40,16);
[0126] It can be seen from Table 3 and Table 4 above that the new data format template changes the field length based on the old data format template, increases the length of the m_cxrCode field by 6 bytes, and increases the length of the m_ruleId field by 2 bytes, so the positions of other fields are also modified accordingly.
[0127] c. Traverse the array OldFieldInfos and get an OldFieldInfo class from the array OldFieldInfos;
[0128] d. Find out whether there is a NewFieldInfo class corresponding to the OldFieldInfo class in the NewFieldInfos array. The OldFieldInfo class and the NewFieldInfo class respectively record the field information of a field in the old data format template and the new data format template. When the field name of the OldFieldInfo class is the same as the field name of the NewFieldInfo class, the OldFieldInfo class corresponds to the NewFieldInfo class, that is, find the common fields of the old data format template and the new data format template;
[0129] If not found, continue to execute step (c) until the traversal ends. If found, execute step (e);
[0130] In this embodiment, the old data format template and the new data format template have 6 common fields, namely, m_prefixId, m_actionCode, m_cxrCode, m_locationCode, m_applicationId, and m_ruleId.
[0131] e. Establish the location mapping relationship of the common fields;
[0132] For any common field, compare its field length in NewFieldInfo with its field length in OldFieldInfo to establish a common field position mapping relationship:
[0133] (1) If the field length of the common field in NewFieldInfo is greater than its field length in OldFieldInfo, the first position mapping relationship of the common field is established as follows:
[0134] ['Field name', OldFieldInfo start position - 1, OldFieldInfo end position - 1, NewFieldInfo start position - 1, NewFieldInfo end position - 1 - (NewFieldInfo field length - OldFieldInfo field length)];
[0135] Among them, OldFieldInfo starting position = the relative starting position of the field in the entire old data format template; OldFieldInfo ending position = the relative ending position of the field in the entire old data format template; NewFieldInfo starting position = the relative starting position of the field in the entire new data format template; NewFieldInfo ending position = the relative ending position of the field in the entire new data format template;
[0136] (2) If the field length of the common field in NewFieldInfo is less than its field length in OldFieldInfo, the second position mapping relationship of the common field is established as follows:
[0137] ['field name', OldFieldInfo start position - 1, OldFieldInfo end position - 1 - (OldFieldInfo field length - NewFieldInfo field length), NewFieldInfo start position - 1, NewFieldInfo end position - 1];
[0138] (3) If the field length of the common field in NewFieldInfo is equal to its field length in OldFieldInfo, the third position mapping relationship of the common field is established as follows:
[0139] ['field name', OldFieldInfo start position - 1, OldFieldInfo end position - 1, NewFieldInfo start position - 1, NewFieldInfo end position - 1];
[0140] The above position mapping relationship of the common fields can be understood as the mapping of the position relationship generated when the common fields are copied and pasted from the old data format template to the new data format template, as shown in Table 5:
[0141]
[0142] Table 5
[0143] In this embodiment, the field information of the field m_prefixId in the old data format template is (m_prefixId, 1, 3, 3), and the field information in the new data format template is (m_prefixId, 1, 3, 3). Since the field lengths are equal, the position mapping relationship of the field m_prefixId is established as shown in Table 6 and abbreviated as [m_prefixId, 0, 2, 0, 2].
[0144]
[0145]
[0146] Table 6
[0147] Correspondingly, the field information of the field m_actionCode in the old data format template is (m_actionCode, 4, 4, 1), and the field information in the new data format template is (m_actionCode, 4, 4, 1). The position mapping relationship of the field m_actionCode is abbreviated as [m_actionCode, 3, 3, 3, 3].
[0148] The field information of the field m_cxrCode in the old data format template is (m_cxrCode, 5, 11, 7), and the field information in the new data format template is (m_cxrCode, 5, 17, 13). The position mapping relationship of the field m_cxrCode is abbreviated as [m_cxrCode, 4, 10, 4, 10].
[0149] The field information of the field m_locationCode in the old data format template is (m_locationCode, 12, 18, 7), and the field information in the new data format template is (m_locationCode, 18, 24, 7). The location mapping relationship of the field m_cxrCode is abbreviated as [m_locationCode, 11, 17, 17, 23].
[0150] The field information of the field m_ruleId in the old data format template is (m_ruleId, 19, 32, 14), and the field information in the new data format template is (m_ruleId, 25, 40, 16). The position mapping relationship for establishing the m_cxrCode field is abbreviated as [m_ruleId, 18, 31, 24, 37].
[0151] The field information of the field m_applicationId in the old data format template is (m_applicationId, 33, 65, 33), and the field information in the new data format template is (m_applicationId, 41, 73, 33). The position mapping relationship for establishing the m_applicationId field is abbreviated as [m_applicationId, 32, 64, 40, 72].
[0152] f. Write the position mapping relationship of each common field into the common field position mapping table according to the field reading order, and store it into the array FieldCorrespondInfos, and then execute step (e);
[0153] The array FieldCorrespondInfos is shown in Table 7, and the position mapping relationship of each common field is stored in sequence according to the field order of the old data format template.
[0154] [m_prefixId,0,2,0,2] [m_actionCode,3,3,3,3] [m_cxrCode,4,10,4,10] [m_locationCode,11,17,17,23] [m_ruleId,18,31,24,37] [m_applicationId,32,64,40,72]
[0155] Table 7
[0156] g. Determine whether the traversal is completed. If so, the process ends.
[0157] 2. Data Processing
[0158] a. Open the domestic freight rate rules text data file in the old data format;
[0159] The file uses the ZIP compression package format, and the ZIP compression package operation uses the code library provided by the system;
[0160] In this embodiment, there are three text data in the domestic freight rate rules text data file in the old data format, numbered 1, 2, and 3, as shown in Table 8.
[0161]
[0162]
[0163] Table 8
[0164] b. Traverse the old data format file and obtain a text data in the old data format;
[0165] For example, the text data of number 1 is obtained, and the length of the text data is 65 bytes.
[0166] c. Create a buffer space NewBuffer, the data length of NewBuffer is the same as the text data length of the new data format;
[0167] In this embodiment, the length of the text data in the new data format is 75 bytes.
[0168] d. Sequentially traverse the array FieldCorrespondInfos generated in step 1, and read therefrom the position mapping relationship of the common fields, wherein the position mapping relationship is one of the first position mapping relationship of the common field, the second position mapping relationship of the common field, and the third position mapping relationship of the common field;
[0169] e. Writing the text data in the old data format into NewBuffer according to the position mapping relationship of the common fields read;
[0170] Specifically, if the first position mapping relationship of the common field is read, the first designated field is extracted from the text data in the first data format, wherein the byte corresponding to the first copy start position is extracted from the text data in the first data format as the first byte of the first designated field, and the byte corresponding to the first copy end position is extracted as the last byte of the first designated field; then the extracted first designated field is written into the cache area, specifically, the first byte of the first designated field is pasted to the corresponding first paste start position, and the last byte of the first designated field is pasted to the corresponding first paste end position;
[0171] If the mapping relationship of the second position of the common field is read, the second designated field is extracted from the text data in the first data format, wherein the byte corresponding to the second copy start position is extracted from the text data in the first data format as the first byte of the second designated field, and the byte corresponding to the second copy end position is extracted as the last byte of the second designated field; then the extracted second designated field is written into the cache area, specifically, the first byte of the second designated field is pasted to the corresponding second paste start position, and the last byte of the second designated field is pasted to the corresponding second paste end position;
[0172] If the third position mapping relationship of the common field is read, the third designated field is extracted from the text data in the first data format, wherein the byte corresponding to the third copy start position is extracted from the text data in the first data format as the first byte of the third designated field, and the byte corresponding to the third copy end position is extracted as the last byte of the third designated field; then the extracted third designated field is written into the cache area, specifically, the first byte of the third designated field is pasted to the corresponding third paste start position, and the last byte of the third designated field is pasted to the corresponding third paste end position;
[0173] In this embodiment, the array FieldCorrespondInfos is traversed, and the position mapping relationship of the field m_prefixId [m_prefixId, 0, 2, 0, 2] is first read, so the text data 0 to 2 bytes of number 1 are copied to 0 to 2 bytes of NewBuffer;
[0174] Secondly, read the position mapping relationship of the field m_actionCode [m_actionCode, 3, 3, 3, 3], and copy the third byte of the text data numbered 1 to the third byte of NewBuffer;
[0175] Secondly, read the position mapping relationship of the field m_cxrCode [m_cxrCode, 4, 10, 4, 10], and copy the 4th to 10th bytes of the text data numbered 1 to the 4th to 10th bytes of NewBuffer;
[0176] Secondly, read the location mapping relationship of the field m_locationCode [m_locationCode, 11, 17, 17, 23], and copy the 11th to 17th bytes of the text data numbered 1 to the 17th to 23rd bytes of NewBuffer;
[0177] Secondly, read the position mapping relationship of the field m_ruleId [m_ruleId, 18, 31, 24, 37], and copy the 18th to 31st bytes of the text data numbered 1 to the 24th to 37th bytes of NewBuffer;
[0178] Secondly, the position mapping relationship [m_applicationId, 32, 64, 40, 72] of the field m_applicationId is read, and the 32nd to 64th bytes of the text data numbered 1 are copied to the 40th to 72nd bytes of NewBuffer.
[0179] The data finally written to NewBuffer is:
[0180] [HXICA12345******LOC1234QWERTY12345678**YUUUU1234567890123456789012345000]
[0181] The above * represents a byte added during the data format conversion process or represents a null byte. In this embodiment, the length of the field m_cxrCode is increased by 6 bytes, and the length of the field m_ruleId is increased by 2 bytes.
[0182] f. Store the contents of NewBuffer into the array NewDatas;
[0183] In this embodiment, the data written into NewBuffer is text data in a new data format, and the array NewDatas is used to store text data in the new data format.
[0184] g. Clear NewBuffer;
[0185] h. Determine whether the traversal of the FieldCorrespondInfos array is complete. If not, continue to execute step (d);
[0186] i. Determine whether the traversal of the old data format file is completed. If so, this process ends.
[0187] In the embodiment of the present invention, according to the same method, the domestic freight rate rule text data in the old data format of No. 2 and No. 3 are format-converted in turn to obtain the corresponding text data in the new data format, as shown in Table 9.
[0188] serial number Domestic freight rate rules text data in new data format 1 HXICA12345******LOC1234QWERTY12345678**YUUUU1234567890123456789012345000 2 MXICA12345******LOC1234QWERTY12345678**YUUUU1234567890123456789012345000 3 KXICA12345******LOC1234QWERTY12345678**YUUUU1234567890123456789012345000
[0189] Table 9
[0190] The data conversion method provided by the implementation of the present invention performs data format conversion on domestic freight rate rule text data, supports operations such as adding fields and changing field lengths during the data format change process, and expands the scope of application. In addition, the domestic freight rate search system is compatible with domestic freight rate rule text data in new data formats and old data formats, so that the freight rate publishing system and the domestic freight rate search system can decouple the format change of the domestic freight rate rule text data, thereby avoiding the impact of the format change of the domestic freight rate rule text data on the effective time of the freight rate data.
[0191] Based on the same inventive concept, an embodiment of the present invention further provides an electronic device, including: a memory and a processor, wherein the processor is used to read and execute a computer program stored in the memory to implement the aforementioned data format conversion method.
[0192] Based on the same inventive concept, an embodiment of the present invention further provides a computer storage medium, wherein the computer storage medium stores computer executable instructions, and the computer executable instructions can implement the aforementioned data format conversion method when executed.
[0193] In the several embodiments provided in the present application, it should be understood that the disclosed devices and methods can be implemented in other ways. For example, the device embodiments described above are only schematic. For example, the division of the modules is only a logical function division. There may be other division methods in actual implementation, such as multiple modules or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, indirect coupling or communication connection of devices or modules, which can be electrical, mechanical or other forms.
[0194] The modules described as separate components may or may not be physically separated, and the components displayed as modules may or may not be physical modules, that is, they may be located in one place, or they may be distributed on multiple network modules. Some or all of the modules may be selected according to actual needs to achieve the purpose of the scheme of this embodiment. In addition, the functional modules in the various embodiments of the present invention may be integrated into a processing module, or each module may exist physically separately, or two or more modules may be integrated into one module. The above-mentioned integrated modules may be implemented in the form of hardware or in the form of software functional modules.
[0195] If the integrated module is implemented in the form of a software function module and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present invention is essentially or the part that contributes to the prior art or all or part of the technical solution can be embodied in the form of a software product. The computer software product is stored in a storage medium, including several instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) to perform all or part of the steps of the method described in each embodiment of the present invention. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), disk or optical disk and other media that can store program codes.
[0196] It should be noted that, for the convenience of description, the aforementioned method embodiments are all described as a series of action combinations, but those skilled in the art should be aware that the present invention is not limited by the described action sequence, because according to the present invention, certain steps can be performed in other sequences or simultaneously. Secondly, those skilled in the art should also be aware that the embodiments described in the specification are all preferred embodiments, and the actions and modules involved are not necessarily required by the present invention.
[0197] In the above embodiments, the description of each embodiment has its own emphasis. For the part not described in detail in a certain embodiment, please refer to the relevant description of other embodiments. Finally, it should be noted that the above description is only a preferred embodiment of the present invention and is not used to limit the present invention. Although the present invention is described in detail with reference to the above embodiments, for those skilled in the art, they can still modify the technical solutions recorded in the above embodiments, or replace some of the technical features therein with equivalents. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present invention should be included in the protection scope of the present invention.
Claims
1. A data format conversion method, characterized in that: The method comprises: Establishing a common field position mapping table, and writing a mapping relationship between a relative position of the common field in the first data format template and its relative position in the second data format template into the common field position mapping table; Based on the common field position mapping table, the text data in the first data format is converted into the text data in the second data format.
2. The method according to claim 1, characterized in that The establishing of the common field position mapping table, writing the mapping relationship between the relative position of the common field in the first data format template and the relative position of the common field in the second data format template into the common field position mapping table, comprises: Obtaining a first data format template, reading the length of the first data format template and field information of each field, including the field name, field length, and the relative starting position and relative ending position of the field in the first data format template; Obtain the second data format template, read the length of the second data format template and field information of each field, including the field name, field length, and the relative starting position and relative ending position of the field in the second data format template; Find common fields, where the common fields are fields with the same field names in the first data format template and the second data format template; Establishing a mapping relationship between a relative position of the common field in the first data format template and its relative position in the second data format template according to the field length of the common field in the first data format template and its field length in the second data format template; According to the field reading order, the mapping relationship of the common fields is written into the common field position mapping table.
3. The method according to claim 2, characterized in that The step of establishing a mapping relationship between a relative position of the common field in the first data format template and its relative position in the second data format template according to the field length of the common field in the first data format template and its field length in the second data format template includes: If the field length of the common field in the first data format template is smaller than the field length of the common field in the second data format template, then establishing a first position mapping relationship of the common field; If the field length of the common field in the first data format template is greater than the field length of the common field in the second data format template, then establishing a second position mapping relationship of the common field; If the field length of the common field in the first data format template is equal to the field length of the common field in the second data format template, a third position mapping relationship of the common field is established.
4. The method according to claim 3, characterized in that The common field first position mapping relationship includes: The field name of the common field; The first copy starting position is the relative starting position of the common field in the first data format template -1; The first copy end position is the relative end position of the common field in the first data format template - 1; The first pasting start position is the relative start position of the common field in the second data format template -1; The first pasting end position is the relative end position of the common field in the second data format template - 1 - (the field length of the common field in the second data format template - the field length of the common field in the first data format template).
5. The method according to claim 4, characterized in that The shared field second position mapping relationship includes: The field name of the common field; The second copy starting position is the relative starting position of the common field in the first data format template -1; The second copy end position is the relative end position of the common field in the first data format template - 1 - (the field length of the common field in the first data format template - the field length of the common field in the second data format template); The second pasting starting position is the relative starting position of the common field in the second data format template -1; The second pasting end position is the relative end position of the common field in the second data format template - 1.
6. The method according to claim 5, characterized in that The third position mapping relationship of the common field includes: The field name of the common field; The third copy starting position is the relative starting position of the common field in the first data format template -1; The third copy end position is the relative end position of the common field in the first data format template -1; The third pasting start position is the relative start position of the common field in the second data format template -1; The third pasting end position is the relative end position of the common field in the second data format template - 1.
7. The method according to claim 6, characterized in that The converting of text data in a first data format into text data in a second data format based on the common field position mapping table includes: Reading text data in a first data format; Traversing the common field position mapping table, and reading mapping relationships in a write order, wherein the mapping relationship is one of a common field first position mapping relationship, a common field second position mapping relationship, and a common field third position mapping relationship; Extracting a specified field from the text data in the first data format according to the read mapping relationship, and writing the specified field into a specified position in the buffer area; After the traversal is completed, the data in the buffer area is stored as text data in the second data format.
8. The method according to claim 7, characterized in that If the first position mapping relationship of the common field is read, the first designated field is extracted from the text data in the first data format, wherein the byte corresponding to the first copy start position is extracted from the text data in the first data format as the first byte of the first designated field, and the byte corresponding to the first copy end position is extracted as the last byte of the first designated field; The extracted first designated field is written into a buffer area, wherein the first byte of the first designated field is pasted to the corresponding first paste start position, and the last byte of the first designated field is pasted to the corresponding first paste end position.
9. The method according to claim 7, characterized in that: Also includes: If the second position mapping relationship of the common field is read, the second designated field is extracted from the text data in the first data format, wherein the byte corresponding to the second copy start position is extracted from the text data in the first data format as the first byte of the second designated field, and the byte corresponding to the second copy end position is extracted as the last byte of the second designated field; The extracted second designated field is written into a buffer area, wherein the first byte of the second designated field is pasted to the corresponding second paste start position, and the last byte of the second designated field is pasted to the corresponding second paste end position.
10. The method according to claim 7, characterized in that Also includes: If the third position mapping relationship of the common field is read, the third designated field is extracted from the text data in the first data format, wherein the byte corresponding to the third copy start position is extracted from the text data in the first data format as the first byte of the third designated field, and the byte corresponding to the third copy end position is extracted as the last byte of the third designated field; The extracted third designated field is written into a buffer area, wherein the first byte of the third designated field is pasted to a corresponding third paste start position, and the last byte of the third designated field is pasted to a corresponding third paste end position.
11. The method according to any one of claims 7 to 10, characterized in that: The length of the buffer area is the same as the length of the text data in the second data format.
12. The method according to any one of claims 7 to 10, characterized in that: After storing the data in the buffer area as text data in the second data format, the method further includes: Clear the buffer area.
13. An electronic device, characterized in that: include: Memory, processor; The processor is used to read and execute the computer program stored in the memory to implement the method according to any one of claims 1 to 12.
14. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores computer-executable instructions, and the computer-executable instructions, when executed, implement the method according to any one of claims 1 to 12.