Data processing method and device based on JavaScript

By automatically detecting and converting long integer data and converting it into strings, JavaScript solves the problem of accuracy loss when processing more than 16-bit long integer data, ensuring the accuracy and integrity of the data.

CN119782005APending Publication Date: 2025-04-08CHINA NAT NUCLEAR POWER CO LTD +1
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411978902.2
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-12-31
Publication Date
2025-04-08

AI Technical Summary

Technical Problem

JavaScript is prone to accuracy loss problems when processing long integer data, especially when the integer length exceeds 16 bits.

Method used

Automatically convert more than 16-bit long integer data that JavaScript cannot correctly process into a string by automatically detecting and converting long integer numeric fields in different system integrations.

Benefits of technology

Ensures the accuracy and integrity of the data, and solves the accuracy loss problem caused by JavaScript processing of long integer data beyond the accuracy range during system integration.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119782005A_ABST
    Figure CN119782005A_ABST
Patent Text Reader

Abstract

The present disclosure belongs to the field of nuclear power technology, and specifically relates to a data processing method and device based on JavaScript. The present disclosure provides a data processing method based on JavaScript, which automatically detects and converts long integer numeric fields in different system integrations, especially automatically converts long integer data with more than 16 bits that cannot be correctly processed by JavaScript into strings, so as to ensure the accuracy and integrity of the data. This solves the problem of precision loss caused by JavaScript processing long integer data beyond the precision range during system integration. It can achieve smooth conversion and intercommunication of multiple data types, and solves the data compatibility problem in enterprise digital system integration.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention belongs to the field of information technology, and in particular relates to a data processing method and device based on JavaScript. Background Art

[0002] The valid range of integers supported by JavaScript is from -2 to the 53rd power to 2 to the 53rd power, that is, -9007199254740992 to 9007199254740992. When the value of the field transmitted between the two systems exceeds this range due to type differences, JavaScript will lose precision when processing long integer data, especially when the integer length exceeds 16 bits. This problem is particularly significant. Summary of the invention

[0003] In order to overcome the problems existing in the related art, a data processing method and device based on JavaScript are provided.

[0004] According to one aspect of an embodiment of the present disclosure, a JavaScript-based data processing method is provided, the method comprising:

[0005] Step 101, receiving a message body to be sent to a second system from a first system, and determining the type of a field in the message body;

[0006] Step 102, determining the fields of the message body that are of digital type as fields to be converted;

[0007] Step 103, converting the value corresponding to the field to be converted into a string, and retaining the original value of other types of fields in the message body to form a processed message body;

[0008] Step 104: Send the processed message body to the second system.

[0009] In a possible implementation, step 102 further includes step 1021, determining fields in the message body whose field names belong to a preset field set as fields to be converted.

[0010] In a possible implementation, step 103 further includes:

[0011] Step 1031, when the structure of the field to be converted is a single-layer JSON structure, directly convert the field to be converted into a string;

[0012] Step 1032: When the structure of the field to be converted is an array structure, the field to be converted is traversed layer by layer and converted into a string.

[0013] In a possible implementation, the conversion mapping relationship is set through a grid pattern or through a custom JSLT script.

[0014] According to another aspect of an embodiment of the present disclosure, a JavaScript-based data processing device is provided, the device comprising:

[0015] A determination module, used for receiving a message body to be sent to a second system from a first system, and determining a type of a field in the message body;

[0016] A determination module, used to determine a field of a digital type in the message body as a field to be converted;

[0017] A conversion module, used for converting the value corresponding to the field to be converted into a string, and retaining the original value of other types of fields in the message body to form a processed message body;

[0018] The sending module is used to send the processed message body to the second system.

[0019] In a possible implementation, the determination module further includes a determination submodule, which is used to determine the fields in the message body whose field names belong to a preset field set as fields to be converted.

[0020] In a possible implementation, the conversion module further includes:

[0021] The first conversion submodule is used to directly convert the field to be converted into a string when the structure of the field to be converted is a single-layer JSON structure;

[0022] The second conversion submodule is used to traverse the field to be converted layer by layer and convert it into a string when the structure of the field to be converted is an array structure.

[0023] In a possible implementation, the conversion mapping relationship is set through a grid pattern or through a custom JSLT script.

[0024] According to another aspect of an embodiment of the present disclosure, a JavaScript-based data processing device is provided, the device comprising:

[0025] processor;

[0026] a memory for storing processor-executable instructions;

[0027] Wherein, the processor is configured to execute the above method.

[0028] According to another aspect of an embodiment of the present disclosure, a non-volatile computer-readable storage medium is provided, on which computer program instructions are stored, and the computer program instructions implement the above method when executed by a processor.

[0029] The beneficial effect of the present disclosure is that: for cross-system integration, the present disclosure provides a JavaScript-based data processing method that automatically detects and converts long integer numeric fields in different system integrations, especially automatically converts long integer data with more than 16 bits that JavaScript cannot correctly process into strings to ensure the accuracy and integrity of the data. This solves the problem of precision loss caused by JavaScript processing long integer data beyond the precision range during system integration. It can achieve smooth conversion and intercommunication of multiple data types, solving the data compatibility problem in enterprise digital system integration. BRIEF DESCRIPTION OF THE DRAWINGS

[0030] Figure 1 The figure is a flowchart of a data processing method based on JavaScript according to an exemplary embodiment.

[0031] Figure 2 The figure is a block diagram of a data processing device based on JavaScript according to an exemplary embodiment. DETAILED DESCRIPTION

[0032] The present invention is further described in detail below with reference to the accompanying drawings and specific embodiments.

[0033] Figure 1 is a flowchart of a data processing method based on JavaScript according to an exemplary embodiment. The method can be executed by a terminal device, for example, the terminal device can be a server, a desktop computer, a laptop computer, etc. The embodiment of the present disclosure does not limit the type of terminal device. Figure 1 As shown, the method includes:

[0034] Step 101: Receive a message body to be sent to a second system from a first system, and determine the type of a field in the message body.

[0035] Step 102: determine the fields of the message body that are of digital type as fields to be converted.

[0036] Step 103: According to a preset conversion mapping relationship, the value corresponding to the field to be converted is converted into a string, and other types of fields in the message body retain their original values ​​to form a processed message body.

[0037] Step 104: Send the processed message body to the second system.

[0038] As an example of this embodiment, during the system integration process, the first system needs to send a message to the second system. The terminal device can receive the message from the first system for preprocessing. The terminal device first determines the type of each field in the received message body, and when it is determined that the field type in the message body is a numeric field, the numeric field is converted into a string according to the user-defined mapping rule. When the terminal device determines that the field type in the message body is not a numeric field, the field is retained and inherited. After traversing and processing each field in the message body, a processed message body that meets the data requirements of the second system is formed and sent to the second system. In this way, the terminal device can automatically identify and convert the field type, and convert the long integer data into a string. In this way, in cross-system communication, the data compatibility between systems is effectively ensured. In particular, in the processing of long integer data, by automatically detecting the field type and converting the numeric data into a string, the problem of precision loss in JavaScript when processing long integer data exceeding 16 bits is effectively avoided.

[0039] In a possible implementation, step 102 also includes step 1021, determining a field in the message body whose field name belongs to a preset field set as a field to be converted, wherein the preset field set includes multiple preset field names, and field names can be added or deleted in the preset field set.

[0040] For example, in an application scenario, the key fields involved in the supplier information system (the first system example) are: supplier basic information: supplierBasic; supplier address: supplierAddress; supplier transaction basis: supplierTxn; supplier bank account: supplierBankAccount; supplier bank account association: supplierBankAccountAssign. Among them, the fields that may involve extra-long numbers include supplierId and branchId. In order to process these fields, a preset field set can be set in a tree structure.

[0041] The terminal device can pre-process the API response results of the supplier information system. First, it determines whether the input message body contains the supplierBankAccount field. If it does, it uses loop logic to process the supplierId and branchId fields in each supplierBankAccount. If these fields are numeric types, they are automatically converted to strings, otherwise the original values ​​are retained. Other fields remain inherited as they are. The test results show that the model mapping successfully converts the over-long numeric fields, ensuring the accuracy and consistency of the data.

[0042] In this way, the present disclosure further abstracts the parameters of the overlong fields. For example, the supplierId and branchId fields are abstracted as variable names. Users do not need to rewrite the code when using model mapping in the future. They only need to pass in the variable names of the overlong fields to achieve the corresponding conversion. This universal component design greatly simplifies the development and maintenance of system integration and improves the flexibility and scalability of the integration process.

[0043] In a possible implementation, step 103 may further include: step 1031 and step 1032 .

[0044] Step 1031, when the structure of the field to be converted is a single-layer JSON structure, directly convert the field to be converted into a string;

[0045] Step 1032: When the structure of the field to be converted is an array structure, the field to be converted is traversed layer by layer and converted into a string.

[0046] For example, when the field to be converted is a single-layer JSON structure, the field of the returned result is directly converted to a string type for subsequent processing. When the field to be converted is an array structure, multi-layer traversal conversion is performed. This flexible mapping method is applicable to various data structures and can dynamically process complex nested JSON messages to ensure the correct conversion of each field during the integration process.

[0047] In a possible implementation, the present disclosure can intuitively set field mapping through a table mode; it can also achieve more flexible and complex data conversion through a custom JSLT script (JSLT can be expressed as a JSON query and transformation language).

[0048] According to another aspect of an embodiment of the present disclosure, a JavaScript-based data processing device is provided, the device comprising:

[0049] A determination module, used for receiving a message body to be sent to a second system from a first system, and determining a type of a field in the message body;

[0050] A determination module, used to determine a field of a digital type in the message body as a field to be converted;

[0051] A conversion module, used for converting the value corresponding to the field to be converted into a string, and retaining the original value of other types of fields in the message body to form a processed message body;

[0052] The sending module is used to send the processed message body to the second system.

[0053] In a possible implementation, the determination module further includes a determination submodule, which is used to determine the fields in the message body whose field names belong to a preset field set as fields to be converted.

[0054] In a possible implementation, the conversion module further includes:

[0055] The first conversion submodule is used to directly convert the field to be converted into a string when the structure of the field to be converted is a single-layer JSON structure;

[0056] The second conversion submodule is used to traverse the field to be converted layer by layer and convert it into a string when the structure of the field to be converted is an array structure.

[0057] In a possible implementation, the conversion mapping relationship is set through a grid pattern or through a custom JSLT script.

[0058] For the description of the above-mentioned device, please refer to the description of the above-mentioned method, which will not be repeated here.

[0059] Figure 2 1900 is a block diagram of a data processing device based on JavaScript according to an exemplary embodiment. For example, the device 1900 can be provided as a server. Figure 2 , the apparatus 1900 includes a processing component 1922, which further includes one or more processors, and a memory resource represented by a memory 1932 for storing instructions, such as an application, that can be executed by the processing component 1922. The application stored in the memory 1932 may include one or more modules, each corresponding to a set of instructions. In addition, the processing component 1922 is configured to execute instructions to perform the above method.

[0060] The device 1900 may also include a power supply component 1926 configured to perform power management of the device 1900, a wired or wireless network interface 1950 configured to connect the device 1900 to a network, and an input / output (I / O) interface 1958. The device 1900 may operate based on an operating system stored in the memory 1932, such as Windows Server™, MacOS X™, Unix™, Linux™, FreeBSD™, or the like.

[0061] In an exemplary embodiment, a non-volatile computer-readable storage medium is also provided, such as a memory 1932 including computer program instructions, which can be executed by the processing component 1922 of the device 1900 to perform the above method.

[0062] The present disclosure may be a system, a method and / or a computer program product. The computer program product may include a computer-readable storage medium carrying computer-readable program instructions for causing a processor to implement various aspects of the present disclosure.

[0063] A computer-readable storage medium may be a tangible device that can hold and store instructions used by an instruction execution device. A computer-readable storage medium may be, for example, but not limited to, an electrical storage device, a magnetic storage device, an optical storage device, an electromagnetic storage device, a semiconductor storage device, or any suitable combination of the foregoing. More specific examples of computer-readable storage media (a non-exhaustive list) include: a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), a static random access memory (SRAM), a portable compact disk read-only memory (CD-ROM), a digital versatile disk (DVD), a memory stick, a floppy disk, a mechanical encoding device, such as a punch card or a raised structure in a groove on which instructions are stored, and any suitable combination of the foregoing. As used herein, a computer-readable storage medium is not to be interpreted as a transient signal per se, such as a radio wave or other freely propagating electromagnetic wave, an electromagnetic wave propagating through a waveguide or other transmission medium (e.g., a light pulse through a fiber optic cable), or an electrical signal transmitted through a wire.

[0064] The computer-readable program instructions described herein can be downloaded from a computer-readable storage medium to each computing / processing device, or downloaded to an external computer or external storage device via a network, such as the Internet, a local area network, a wide area network, and / or a wireless network. The network can include copper transmission cables, optical fiber transmissions, wireless transmissions, routers, firewalls, switches, gateway computers, and / or edge servers. The network adapter card or network interface in each computing / processing device receives the computer-readable program instructions from the network and forwards the computer-readable program instructions for storage in the computer-readable storage medium in each computing / processing device.

[0065] The computer program instructions for performing the operation of the present disclosure may be assembly instructions, instruction set architecture (ISA) instructions, machine instructions, machine-related instructions, microcode, firmware instructions, state setting data, or source code or object code written in any combination of one or more programming languages, including object-oriented programming languages, such as Smalltalk, C++, etc., and conventional procedural programming languages, such as "C" language or similar programming languages. Computer-readable program instructions may be executed completely on a user's computer, partially on a user's computer, as an independent software package, partially on a user's computer, partially on a remote computer, or completely on a remote computer or server. In the case of a remote computer, the remote computer may be connected to the user's computer via any type of network, including a local area network (LAN) or a wide area network (WAN), or may be connected to an external computer (e.g., using an Internet service provider to connect via the Internet). In some embodiments, an electronic circuit, such as a programmable logic circuit, a field programmable gate array (FPGA), or a programmable logic array (PLA), may be customized by utilizing the state information of the computer-readable program instructions, and the electronic circuit may execute the computer-readable program instructions, thereby realizing various aspects of the present disclosure.

[0066] Various aspects of the present disclosure are described herein with reference to the flowcharts and / or block diagrams of the methods, devices (systems) and computer program products according to the embodiments of the present disclosure. It should be understood that each box in the flowchart and / or block diagram and the combination of each box in the flowchart and / or block diagram can be implemented by computer-readable program instructions.

[0067] These computer-readable program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, or other programmable data processing device, thereby producing a machine, so that when these instructions are executed by the processor of the computer or other programmable data processing device, a device that implements the functions / actions specified in one or more boxes in the flowchart and / or block diagram is generated. These computer-readable program instructions can also be stored in a computer-readable storage medium, and these instructions cause the computer, programmable data processing device, and / or other equipment to work in a specific manner, so that the computer-readable medium storing the instructions includes a manufactured product, which includes instructions for implementing various aspects of the functions / actions specified in one or more boxes in the flowchart and / or block diagram.

[0068] Computer-readable program instructions may also be loaded onto a computer, other programmable data processing apparatus, or other device so that a series of operating steps are performed on the computer, other programmable data processing apparatus, or other device to produce a computer-implemented process, thereby causing the instructions executed on the computer, other programmable data processing apparatus, or other device to implement the functions / actions specified in one or more boxes in the flowchart and / or block diagram.

[0069] The flow chart and block diagram in the accompanying drawings show the possible architecture, function and operation of the system, method and computer program product according to multiple embodiments of the present disclosure. In this regard, each square box in the flow chart or block diagram can represent a part of a module, program segment or instruction, and a part of the module, program segment or instruction includes one or more executable instructions for realizing the specified logical function. In some alternative implementations, the function marked in the square box can also occur in a sequence different from that marked in the accompanying drawings. For example, two continuous square boxes can actually be executed substantially in parallel, and they can sometimes be executed in reverse order, depending on the functions involved. It should also be noted that each square box in the block diagram and / or flow chart, and the combination of the square boxes in the block diagram and / or flow chart can be implemented with a dedicated hardware-based system that performs the specified function or action, or can be implemented with a combination of special hardware and computer instructions.

[0070] The embodiments of the present disclosure have been described above, and the above description is exemplary, not exhaustive, and is not limited to the disclosed embodiments. Many modifications and changes will be apparent to those of ordinary skill in the art without departing from the scope and spirit of the described embodiments. The selection of terms used herein is intended to best explain the principles of the embodiments, practical applications, or improvements to the technology in the market, or to enable other persons of ordinary skill in the art to understand the embodiments disclosed herein.

Claims

1. A data processing method based on JavaScript, characterized in that: The method comprises: Step 101, receiving a message body to be sent to a second system from a first system, and determining the type of a field in the message body; Step 102, determining the fields of the message body that are of digital type as fields to be converted; Step 103, according to a preset conversion mapping relationship, the value corresponding to the field to be converted is converted into a string, and other types of fields in the message body retain the original values ​​to form a processed message body; Step 104: Send the processed message body to the second system.

2. The method according to claim 1, characterized in that Step 102 also includes step 1021, determining the fields in the message body whose field names belong to a preset field set as fields to be converted.

3. The method according to claim 1, characterized in that Step 103 also includes: Step 1031, when the structure of the field to be converted is a single-layer JSON structure, directly convert the field to be converted into a string; Step 1032: When the structure of the field to be converted is an array structure, the field to be converted is traversed layer by layer and converted into a string.

4. The method according to claim 1, characterized in that Set the transformation mapping via a grid pattern or via a custom JSLT script.

5. A data processing device based on JavaScript, characterized in that: The device comprises: A determination module, used for receiving a message body to be sent to a second system from a first system, and determining a type of a field in the message body; A determination module, used to determine a field of a digital type in the message body as a field to be converted; A conversion module, used to convert the value corresponding to the field to be converted into a string according to a preset conversion mapping relationship, and retain the original value of other types of fields in the message body to form a processed message body; The sending module is used to send the processed message body to the second system.

6. The device according to claim 1, characterized in that The determination module also includes a determination submodule, which is used to determine the fields in the message body whose field names belong to a preset field set as fields to be converted.

7. The device according to claim 1, characterized in that The conversion module also includes: The first conversion submodule is used to directly convert the field to be converted into a string when the structure of the field to be converted is a single-layer JSON structure; The second conversion submodule is used to traverse the field to be converted layer by layer and convert it into a string when the structure of the field to be converted is an array structure.

8. The device according to claim 5, characterized in that Set the transformation mapping via a grid pattern or via a custom JSLT script.

9. A data processing device based on JavaScript, characterized in that: The device comprises: processor; a memory for storing processor-executable instructions; The processor is configured to execute the method according to any one of claims 1 to 3.

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