Data storage method and device, data query method and device, electronic equipment and medium
By comparing the service data to be stored with the valid data stored in the database, and only updating the database when the numerical value changes, the problem of low data storage and query efficiency in energy storage services is solved, and efficient data storage and query are achieved.
Patent Information
- Application Number
- CN202411963862.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-30
- Publication Date
- 2025-04-29
AI Technical Summary
In energy storage business, the storage and query efficiency of massive business data is low, resulting in degradation of database performance, wasted storage space, and reduced data query efficiency.
By acquiring the service data to be stored and the valid data stored in the database for comparison, the database is updated only when the value of the service field changes, repeated storage is avoided, and the data is periodically acquired and stored using the MQTT communication protocol.
It effectively avoids duplicate storage of the same data, improves the efficiency of data storage and the utilization of database storage space, and improves the efficiency of data query.
Smart Images

Figure CN119903051A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the technical field of data storage, and in particular to a data storage method, a data query method, a device, an electronic device and a medium. Background Art
[0002] Energy storage services usually involve massive amounts of business data, and databases are mainly used to store these massive amounts of business data.
[0003] Every time data is stored in the database, a large number of operations need to be performed on the database, which will lead to a decrease in database performance, such as reduced storage efficiency. In addition, in some business scenarios, business data needs to be stored regularly. For example, the voltage and current of the battery are stored in the database regularly. If a certain type of business data has not changed for a period of time, this type of business data still needs to be stored regularly during this period of time. The data stored in the database for this type of business data is the same, which will undoubtedly waste the storage space of the database. In addition, when querying this type of business data from the database, since the database stores a lot of duplicate data, the efficiency of data query will also be reduced.
[0004] Accordingly, the art needs a new technical solution to solve the above problems. Summary of the invention
[0005] In order to overcome the above-mentioned defects, the present application is proposed to solve or at least partially solve the technical problem of improving data storage efficiency and storage space utilization.
[0006] In a first aspect, a method for storing business data is provided, wherein the business data includes a plurality of business fields, and the method includes:
[0007] Acquire first business data to be stored;
[0008] Acquire second business data stored in a database, wherein the value of each business field in the second business data is a valid value of each business field, and the valid value is a valid value last stored in the database before a first target time, and the first target time is a time when the first business data is acquired;
[0009] Comparing the values of each service field in the first service data and the second service data;
[0010] If the values of the business field in the first business data and the second business data are different, storing the value of the business field in the first business data as a valid value of the business field at the first target time in the database;
[0011] If the value of the service field in the first service data is the same as that in the second service data, the value of the service field in the first service data is not stored in the database.
[0012] In a technical solution of the above-mentioned method for storing business data, the method includes:
[0013] If the value of the service field in the first service data and the second service data is the same,
[0014] Then, according to the default value NULL of the database, the value of the business field in the database at the first target time is set.
[0015] In a technical solution of the above-mentioned method for storing business data, the obtaining of the first business data to be stored includes: periodically obtaining the first business data according to a preset first time interval.
[0016] In a technical solution of the above-mentioned method for storing business data, the third business data to be stored is periodically acquired according to a preset second time interval;
[0017] storing the values of each service field in the third service data as the valid values of each service field at the second target moment in the database;
[0018] in,
[0019] The second target time is the time at which the third service data is acquired;
[0020] The preset second time interval is greater than the preset first time interval.
[0021] In a technical solution of the above-mentioned business data storage method, the preset first time interval is 1 second, and the preset second time interval is 1 hour.
[0022] In a technical solution of the above-mentioned method for storing business data, the method includes:
[0023] Using the MQTT communication protocol to establish a communication connection with a business device, the business device is used to provide the business data;
[0024] Based on the communication connection, the first service data and / or the third service data are acquired from the service data provided by the service device.
[0025] In a second aspect, a method for querying business data is provided, wherein the business data includes a plurality of business fields, and the business data is stored in a database using the business data storage method provided in the first aspect, and the method includes:
[0026] Receive data query requests;
[0027] According to the data query request, query and output the fourth business data stored in the database;
[0028] in,
[0029] The value of each service field in the fourth service data is a valid value of each service field, and the valid value is a valid value last stored in the database before the third target time;
[0030] The third target time is the time at which the data query request is received.
[0031] In a third aspect, a storage device for business data is provided, wherein the business data includes a plurality of business fields, and the device includes:
[0032] A first data acquisition module, configured to acquire first business data to be stored;
[0033] A second data acquisition module is configured to acquire second business data stored in a database, wherein the value of each business field in the second business data is a valid value of each business field, and the valid value is a valid value last stored in the database before a first target time, and the first target time is the time when the first business data is acquired;
[0034] A data comparison processing module, configured to compare the values of each business field in the first business data and the second business data;
[0035] If the values of the business field in the first business data and the second business data are different, storing the value of the business field in the first business data as a valid value of the business field at the first target time in the database;
[0036] If the value of the service field in the first service data is the same as that in the second service data, the value of the service field in the first service data is not stored in the database.
[0037] In a fourth aspect, a device for querying business data is provided, wherein the business data includes a plurality of business fields, and the business data is stored in a database using the business data storage method provided in the second aspect, and the query device includes:
[0038] A request receiving module, which is configured to receive a data query request;
[0039] a data query module, configured to query and output fourth business data stored in the database according to the data query request;
[0040] in,
[0041] The value of each service field in the fourth service data is a valid value of each service field, and the valid value is a valid value last stored in the database before the third target time;
[0042] The third target time is the time at which the data query request is received.
[0043] In a fifth aspect, an electronic device is provided, comprising at least one processor; and a memory communicatively connected to the at least one processor; wherein a computer program is stored in the memory, and when the computer program is executed by the at least one processor, the method described in any one of the technical solutions of the above-mentioned business data storage or query method is implemented.
[0044] In a sixth aspect, a computer-readable storage medium is provided, which stores a plurality of program codes, wherein the program codes are suitable for being loaded and run by a processor to execute the method described in any one of the technical solutions of the above-mentioned business data storage or query method.
[0045] The above one or more technical solutions of the present application have at least one or more of the following beneficial effects:
[0046] In a technical solution for implementing a business data storage method provided by the present application, the business data includes multiple business fields, and the method includes: obtaining first business data to be stored; obtaining second business data stored in a database, the value of each business field in the second business data is a valid value of each business field, the valid value is a valid value last stored in the database before a first target time, and the first target time is the time when the first business data is obtained; comparing the values of each business field in the first business data and the second business data; if the value of the business field in the first business data is different from that in the second business data, it indicates that the value of the business field has changed, and at this time, the value of the business field in the first business data can be stored in the database as the valid value of the business field at the first target time; if the value of the business field in the first business data is the same as that in the second business data, it indicates that the value of the business field has not changed, and the value of the business field in the first business data is not stored in the database.
[0047] Through the above implementation scheme, field-level data storage is achieved, and the value of the business field can be stored when the value of the business field changes, and the value of the business field is not stored when the value of the business field does not change. Based on this, repeated storage of the same data can be effectively avoided, and the efficiency of data storage and the utilization rate of database storage space are improved. In addition, since the database does not store duplicate data, it is also conducive to improving the efficiency of data query on the database.
[0048] In a technical solution for implementing a business data query method provided in the present application, the business data includes multiple business fields, and the business data is stored in a database using the aforementioned storage method. The query method includes: receiving a data query request; querying and outputting fourth business data stored in the database according to the data query request; wherein the value of each business field in the fourth business data is a valid value of each business field, and the valid value is the last valid value stored in the database before the third target time; the third target time is the time when the data query request is received.
[0049] In the above implementation scheme, the business data in the database is stored using the aforementioned storage method, so the database does not store duplicate data, so when performing data query on the database, the efficiency of data query can be significantly improved. BRIEF DESCRIPTION OF THE DRAWINGS
[0050] The disclosure of the present application will become easier to understand with reference to the accompanying drawings. It is easy for those skilled in the art to understand that these drawings are only for illustrative purposes and are not intended to limit the scope of protection of the present application. Among them:
[0051] Figure 1 This is a flowchart of the main steps of a method for storing business data according to an embodiment of the present application;
[0052] Figure 2 This is a schematic diagram of the main steps of storing full service data in a timely manner according to an embodiment of the present application;
[0053] Figure 3 This is a schematic diagram of the overall process of a business data storage method according to an embodiment of the present application;
[0054] Figure 4 yes Figure 3 Schematic diagram of the main steps of data comparison in the overall process shown;
[0055] Figure 5 yes Figure 3 A schematic diagram of the main steps of storing the entire amount of business data in the overall process shown;
[0056] Figure 6This is a flowchart of the main steps of a method for querying business data according to an embodiment of the present application;
[0057] Figure 7 is a schematic diagram of the main structure of a storage device for business data according to an embodiment of the present application;
[0058] Figure 8 is a schematic diagram of the main structure of a device for querying business data according to an embodiment of the present application;
[0059] Fig. 9 It is a schematic diagram of the main structure of an electronic device according to an embodiment of the present application.
[0060] Reference numerals:
[0061] 11: first data acquisition module; 12: second data acquisition module; 13: data comparison and processing module; 21: request receiving module; 22: data query module; 31: memory; 32: processor. DETAILED DESCRIPTION
[0062] Some embodiments of the present application are described below with reference to the accompanying drawings. Those skilled in the art should understand that these embodiments are only used to explain the technical principles of the present application and are not intended to limit the protection scope of the present application.
[0063] In the description of the present application, "module" and "processor" may include hardware, software or a combination of the two. A module may include hardware circuits, various suitable sensors, communication ports, and memories, and may also include software parts, such as program codes, or a combination of software and hardware. The processor may be a central processing unit, a microprocessor, an image processor, a digital signal processor, or any other suitable processor. The processor has data and / or signal processing functions. The processor may be implemented in software, hardware, or a combination of the two. Computer-readable storage media include any suitable media that can store program codes, such as a disk, a hard disk, an optical disk, a flash memory, a read-only memory, a random access memory, and the like. The term "A and / or B" represents all possible combinations of A and B, such as just A, just B, or A and B.
[0064] Here we first explain some terms involved in this application.
[0065] Business data can be understood as data generated when executing business processing. A piece of business data can be composed of multiple different types of data from the same business device, or the same type of data from multiple different business devices. However, no matter which composition method is used, a piece of business data includes multiple business fields, each of which records the value of a type of data.
[0066] In some embodiments, the service may be an energy storage service, and the service data may consist of multiple different types of data of the same energy storage device. For example, a service field in a service data may include the voltage, current, temperature, etc. of the same energy storage device. In some embodiments, the service may be an energy storage service, and the service data may consist of the same type of data of multiple different service devices. For example, a service field in a service data may include the voltages of N energy storage devices, where N>1.
[0067] The following is a description of an embodiment of a method for storing business data provided by the present application.
[0068] See attached Figure 1 , Figure 1 FIG. 1 is a flow chart showing the main steps of a method for storing business data according to an embodiment of the present application. Figure 1 As shown, the method for storing business data in the embodiment of the present application mainly includes the following steps S101 to S105.
[0069] Step S101: Acquire first service data to be stored.
[0070] The first business data may be understood as business data that has not yet been stored in the database and needs to be stored.
[0071] In some embodiments, the first service data may be periodically acquired according to a preset first time interval. The first time interval is a time value. The smaller the first time interval, the higher the frequency of acquiring the first service data, and vice versa. Based on this, when setting the value of the first time interval, those skilled in the art may first determine the frequency of acquiring the first service data, and then set the value of the first time interval according to the acquisition frequency. In some embodiments, the first time interval is 1 second.
[0072] In some implementations, the business data may be provided by a business device that performs business processing. When acquiring the first business data, the MQTT (Message Queuing Telemetry Transport) communication protocol may be used to establish a communication connection with the business device, and then based on the communication connection, the first business data may be acquired from the business data provided by the business device. The MQTT communication protocol has the advantages of being lightweight, efficient, and highly secure. Therefore, the first business data may be acquired quickly and securely based on the above communication connection.
[0073] Step S102: Acquire the second business data stored in the database, the value of each business field in the second business data is the valid value of each business field, the valid value is the valid value last stored in the database before the first target time, and the first target time is the acquisition time of the first business data.
[0074] Different from the first business data, the second business data can be understood as business data that has been stored in the database, rather than business data that has not yet been stored in the database.
[0075] In some embodiments, the database is a TDengine database, which is a time series database with strong data writing, querying, and storage performance. Therefore, using the TDengine database to store business data can further improve the storage efficiency of business data. This embodiment does not elaborate on the functional structure and usage of the TDengine database.
[0076] Step S103: Compare the values of each service field in the first service data and the second service data.
[0077] If the value of the service field in the first service data is different from that in the second service data, go to step S104; otherwise, go to step S105.
[0078] Step S104: storing the value of the business field in the first business data in the database as the valid value of the business field at the first target moment.
[0079] If the values of the business field in the first and second business data are different, it indicates that the value of the business field has changed. The value of the business field in the first business data is the latest value, and the latest value needs to be stored in the database to ensure that the values stored in the database are the latest.
[0080] Step S105: Do not store the value of the business field in the first business data in the database.
[0081] If the value of the business field in the first and second business data is the same, it indicates that the value of the business field has not changed, and the value of the business field in the second business data is still the latest value. Therefore, there is no need to store the value of the business field in the first business data in the database. This can avoid storing duplicate data in the database, improve data storage efficiency and reduce storage space utilization.
[0082] Based on the method described in the above steps S101 to S105, field-level data storage is implemented. The value of the business field can be stored when the value of the business field changes, and the value of the business field is not stored when the value of the business field does not change. This storage method can be understood as staggered storage. Based on this, it can not only ensure that the values stored in the database are the latest, but also effectively avoid repeated storage of the same data, thereby improving the efficiency of data storage and the utilization of database storage space. For example, a complete first business data is 1kb in size, and the business field whose value changes in this first business data is only 2bit. Compared with storing 1kb of data in the database, storing 2bit of data in the database can greatly reduce the number of data operations, improve the efficiency of data storage, and also save storage space and avoid storage space waste.
[0083] In addition, since the number of data operations is reduced, the burden on the database can also be reduced, further improving the efficiency of using the database to store data; when there are many business fields that need to be stored, it may cause errors in the database operation program, thereby requiring the business fields to be re-stored, wasting storage time, but the above method only needs to store business fields with changed values, therefore, it can reduce the occurrence of the above situation and further improve storage efficiency.
[0084] In addition, since the database does not store duplicate data, it is also helpful to improve the efficiency of data query on the database.
[0085] The following is a description of an embodiment of the method for storing business data provided by the present application.
[0086] In some implementations of the above step S105, if the value of the business field in the first and second business data is the same, the value of the business field in the database at the first target moment can be set according to the default value NULL of the database. The default value NULL indicates that the value is undefined. If the value of the business field is found to be the default value NULL, it indicates that the value of the business field at the first target moment is undefined, and thus it can be determined that the value of the business field at the first target moment is the same as the valid value last stored in the database before the first target moment. Since the storage space occupied by the default value NULL is very small, it is much smaller than the value of the business field in the first business data. In addition, setting the default value NULL does not require a long time, which is much smaller than the time to store the value of the business field in the first business data in the database, and therefore, the efficiency of data storage and the utilization of database storage space can also be improved.
[0087] Refer to Table 1 below, which takes the energy storage business as an example to explain the values stored in the database.
[0088] Table 1
[0089]
[0090]
[0091] The business fields v1 to v201 represent the voltages of 201 energy storage devices respectively. The values at time t0, t1, and t2 are the values of the business fields stored for the first, second, and third time respectively.
[0092] The following description takes the business field v1 as an example.
[0093] The value obtained at time t0 is 3.0, so the value of business field v1 at time t0 stored in the database is 3.0.
[0094] The value obtained at time t1 is 3.0. Before time t1, the valid value of the business field v1 in the database is 3.0. Since the value at time t1 is the same as the valid value, the value of the business field v1 at time t1 stored in the database is set according to the default value of the database, NULL.
[0095] The value obtained at time t2 is 3.2. Before time t2, the valid value of the business field v1 in the database is 3.0. Since the value at time t2 is different from the valid value, the value at time t2 is stored in the database as the valid value at time t2, that is, the value of the business field v1 stored in the database at time t2 is 3.2.
[0096] The following is a description of an embodiment of the method for storing business data provided by the present application.
[0097] In some embodiments according to the present application, Figure 2 The following steps S201 to S202 are shown to store the full amount of business data in a timely manner.
[0098] Step S201: periodically obtain third service data to be stored according to a preset second time interval. The third service data can be understood as service data that has not been stored in the database and needs to be stored.
[0099] In some implementations, the business data may be provided by a business device that performs business processing. When acquiring the third business data, the MQTT communication protocol may also be used to establish a communication connection with the business device, and then based on the communication connection, the third business data may be acquired from the business data provided by the business device, thereby improving the acquisition efficiency and security of the third business data.
[0100] Step S202: storing the values of each service field in the third service data in the database as the valid values of each service field at the second target moment.
[0101] The second target time is the time for acquiring the third service data.
[0102] Unlike the aforementioned method embodiment that stores the first business data, this embodiment does not filter the third business data, but stores all the acquired third business data in the database. Therefore, this embodiment can also be understood as a full storage of business data.
[0103] The preset second time interval is a time value, and the smaller the second time interval is, the higher the frequency of obtaining the third service data is, and vice versa. Based on this, when setting the value of the second time interval, those skilled in the art can first determine the frequency of obtaining the third service data, and then set the value of the third time interval according to the frequency of obtaining.
[0104] In addition, according to the description of the above method embodiment, in some embodiments, the first service data can be periodically obtained according to a preset first time interval. If the third service data to be stored is periodically obtained according to a preset second time interval, the second time interval needs to be greater than the first time interval. In some embodiments, the first time interval is 1 second and the second time interval is 1 hour.
[0105] Based on the method described in step S201 to step S202, the business data can be stored in full and on a regular basis to prevent data loss. In addition, if the method cannot be successfully executed, it indicates that the communication connection may be abnormal. Therefore, the business data can be stored in full and on a regular basis by the method, which can also be used as a heartbeat signal to monitor the status of the communication connection.
[0106] The following is combined with Figure 3 To Attachment Figure 5 , the business data storage method provided by this application is explained.
[0107] First, refer to the attached Figure 3 , Figure 3 The overall process of the business data storage method is exemplified, and the data source can be understood as the data provided by the business device. Figure 3 As shown, the business data can be stored through the following steps S301 to S303.
[0108] Step S301: data pulling.
[0109] Specifically, the first service data can be periodically obtained from the data source according to a preset first time interval. The first time interval is 1 second. In addition, the second service data stored in the database is also obtained.
[0110] Step S302: data comparison.
[0111] Specifically, the values of each service field in the first and second service data are compared.
[0112] Step S303: Data storage.
[0113] Specifically, according to the result of the above comparison, the data is stored in the database. If the values of the business field in the first and second business data are different, the value of the business field in the first business data is stored in the database as the valid value of the business field at the first target time; otherwise, the value of the business field in the first business data is not stored in the database.
[0114] The meanings of the first service data, the second service data, the service field, and the first target time are respectively the same as the meanings of the relevant terms in the aforementioned method embodiment, and are not repeated here.
[0115] Based on the method described in steps S301 to S303 above, it is possible to ensure that the values stored in the database are all up to date and to effectively avoid repeated storage of the same data, thereby improving the efficiency of data storage and the utilization of database storage space.
[0116] Then refer to the attached Figure 4 , Figure 4 The main steps of data comparison in the above overall process are shown as an example. Figure 4 As shown, data comparison can be performed through the following steps S3021 to S3023.
[0117] Step S3021: Determine whether the value of the business field has changed; if changed, go to step S3022; if not changed, go to step S3023.
[0118] Specifically, if the values of the service field in the first and second service data are different, the value of the service field changes; otherwise, the value of the service field does not change.
[0119] Step S3022: Set the default value NULL for the field.
[0120] Specifically, according to the default value NULL of the database, the value of the business field in the database at the first target time is set.
[0121] Step S3023: Set a valid value for the field.
[0122] Specifically, the value of the business field in the first business data is stored in the database as a valid value of the business field at the first target moment.
[0123] Based on the method described in steps S3021 to S3023 above, the storage value of the business field in the database can be flexibly adjusted according to the change in the value of the business field. It can also ensure that the values stored in the database are the latest, avoid repeated storage of the same data, and improve the efficiency of data storage and the utilization of database storage space.
[0124] Finally, see Appendix Figure 5 , Figure 5 The main steps of storing all business data are shown in the following example. Figure 5 As shown, the business data can be fully stored through the following steps S401 to S402.
[0125] Step S401: Pull all data.
[0126] Specifically, according to a preset second time interval, the third service data to be stored is periodically obtained from the data source, and the second time interval is 1 hour.
[0127] Step S402: storing all data.
[0128] Specifically, the value of each service field in the third service data is stored in the database as a valid value of each service field at the second target moment.
[0129] The meanings of the third service data and the second target time are respectively the same as the meanings of the relevant terms in the aforementioned method embodiment, and are not repeated here.
[0130] Based on the method described in steps S401 to S402 above, it is possible to achieve regular full storage of business data.
[0131] The following is a description of an embodiment of the method for querying business data provided by the present application.
[0132] See attached Figure 6 , Figure 6 FIG. 1 is a flow chart of the main steps of a method for querying business data according to an embodiment of the present application. The business data in the embodiment is stored in a database using the storage method described in the above method embodiment. Figure 6 As shown, the method for querying business data in the embodiment of the present application mainly includes the following steps S501 to S502.
[0133] Step S501: receiving a data query request.
[0134] Data query requests are used to request business data in the database.
[0135] Step S502: According to the data query request, query and output the fourth business data stored in the database.
[0136] The value of each business field in the fourth business data is a valid value of each business field, and the valid value is the valid value last stored in the database before the third target time, and the third target time is the time when the data query request is received. In other words, the value of the business field in the fourth business data is the latest valid value.
[0137] According to the description of the aforementioned storage method embodiment, the database may be a TDengine database. In this case, the last function of the TDengine database may be reused to execute step S502 to obtain the latest valid value of each business field from the TDengine database.
[0138] Based on the method described in steps S501 to S502 above, the latest valid value of each business field stored in the database can be obtained efficiently and reliably.
[0139] It should be pointed out that although the various steps in the above embodiments are described in a specific order, those skilled in the art can understand that in order to achieve the effect of the present application, different steps do not have to be executed in such an order. They can be executed simultaneously (in parallel) or in other orders. These adjusted schemes are equivalent to the technical schemes described in this application, and therefore will also fall within the scope of protection of this application.
[0140] It is understood by those skilled in the art that all or part of the processes in the method for implementing the above-mentioned embodiment of the present application can also be completed by instructing the relevant hardware through a computer program, and the computer program can be stored in a computer-readable storage medium, and the computer program can implement the steps of the above-mentioned various method embodiments when executed by the processor. Among them, the computer program includes computer program code, and the computer program code can be in source code form, object code form, executable file or some intermediate form. The computer-readable storage medium may include: any entity or device, medium, U disk, mobile hard disk, disk, optical disk, computer memory, read-only memory, random access memory, electric carrier signal, telecommunication signal and software distribution medium, etc. that can carry the computer program code.
[0141] Another aspect of the present application also provides a storage device for business data.
[0142] See attached Figure 7 , Figure 7FIG. 1 is a main structural block diagram of a storage device for service data according to an embodiment of the present application. Figure 7 As shown, the storage device for business data mainly includes a first data acquisition module 11, a second data acquisition module 12 and a data comparison processing module 13. In some embodiments, one or more of the first data acquisition module 11, the second data acquisition module 12 and the data comparison processing module 13 can be combined into one module. In some embodiments, the first data acquisition module 11 can be configured to acquire the first business data to be stored; the second data acquisition module 12 can be configured to acquire the second business data stored in the database, the value of each business field in the second business data is the valid value of each business field, the valid value is the valid value last stored in the database before the first target time, and the first target time is the acquisition time of the first business data; the data comparison processing module 13 can be configured to compare the values of each business field in the first business data and the second business data; if the value of the business field in the first business data is different from that in the second business data, the value of the business field in the first business data is stored in the database as the valid value of the business field at the first target time; if the value of the business field in the first business data is the same as that in the second business data, the value of the business field in the first business data is not stored in the database. In one implementation, the description of the specific implementation functions can refer to step S101 to step S105.
[0143] The storage device of the above business data is used to execute Figures 1 to 5 The business data storage method embodiment shown in the figure has similar technical principles, technical problems solved and technical effects produced. Technical personnel in this technical field can clearly understand that for the convenience and conciseness of description, the specific working process and related instructions of the business data storage device can refer to the contents described in the embodiment of the business data storage method, which will not be repeated here.
[0144] Another aspect of the present application also provides a device for querying business data.
[0145] See attached Figure 8 , Figure 8 FIG. 1 is a main structural block diagram of a service data query device according to an embodiment of the present application. In this embodiment, service data is stored in a database using the service data storage method described in the above method embodiment. Figure 8As shown, the query device for business data mainly includes a request receiving module 21 and a data query module 22. In some embodiments, the request receiving module 21 and the data query module 22 can be combined into one module. In some embodiments, the request receiving module 21 can be configured to receive a data query request; the data query module can be configured to query and output the fourth business data stored in the database according to the data query request; wherein the value of each business field in the fourth business data is a valid value of each business field, and the valid value is the valid value last stored in the database before the third target time; the third target time is the time of receiving the data query request. In one embodiment, the description of the specific implementation function can be referred to the description of steps S501 to S502.
[0146] The query device for the above business data is used to execute Figure 6 The business data query method embodiment shown in the figure has similar technical principles, technical problems solved and technical effects produced. Technical personnel in this technical field can clearly understand that for the convenience and conciseness of description, the specific working process and related instructions of the business data query device can refer to the contents described in the embodiment of the business data query method, which will not be repeated here.
[0147] Another aspect of the present application also provides a computer-readable storage medium.
[0148] In an embodiment of a computer-readable storage medium according to the present application, the computer-readable storage medium may be configured to store a program for storing or querying the business data of the above-mentioned method embodiment, and the program may be loaded and run by the processor to implement the above-mentioned business data storage or query method. For ease of explanation, only the parts related to the embodiment of the present application are shown. For specific technical details not disclosed, please refer to the method part of the embodiment of the present application. The computer-readable storage medium may be a storage device formed by various electronic devices. Optionally, the computer-readable storage medium in the embodiment of the present application is a non-temporary computer-readable storage medium.
[0149] Another aspect of the present application provides an electronic device.
[0150] In an embodiment of an electronic device according to the present application, the electronic device may include at least one processor; and a memory connected to the at least one processor in communication; wherein a computer program is stored in the memory, and when the computer program is executed by the at least one processor, the method described in any of the above embodiments is implemented. Fig. 9 , Fig. 9 It is exemplarily shown that the memory 31 and the processor 32 are communicatively connected via a bus.
[0151] In some embodiments of the present application, the electronic device may be, but is not limited to, a desktop, a laptop, a handheld computer, a notebook computer, an ultra-mobile personal computer (UMPC), a netbook, a personal digital assistant (PDA), etc., and the embodiments of the present application are not limited thereto.)
[0152] So far, the technical solution of the present application has been described in conjunction with an embodiment shown in the accompanying drawings, but it is easy for those skilled in the art to understand that the protection scope of the present application is obviously not limited to these specific embodiments. Without departing from the principles of the present application, those skilled in the art can make equivalent changes or substitutions to the relevant technical features, and the technical solutions after these changes or substitutions will fall within the protection scope of the present application.
Claims
1. A method for storing business data, characterized in that: The business data includes a plurality of business fields, and the method includes: Acquire first business data to be stored; Acquire second business data stored in a database, wherein the value of each business field in the second business data is a valid value of each business field, and the valid value is a valid value last stored in the database before a first target time, and the first target time is a time when the first business data is acquired; Comparing the values of each service field in the first service data and the second service data; If the values of the business field in the first business data and the second business data are different, storing the value of the business field in the first business data as a valid value of the business field at the first target time in the database; If the value of the service field in the first service data is the same as that in the second service data, the value of the service field in the first service data is not stored in the database.
2. The method according to claim 1, characterized in that The method comprises: If the value of the service field in the first service data and the second service data is the same, Then, according to the default value NULL of the database, the value of the business field in the database at the first target time is set.
3. The method according to claim 1, characterized in that: The obtaining of the first service data to be stored includes: The first service data is periodically acquired according to a preset first time interval.
4. The method according to claim 3, characterized in that: The method comprises: periodically acquiring the third service data to be stored according to a preset second time interval; storing the values of each service field in the third service data as the valid values of each service field at the second target moment in the database; in, The second target time is the time at which the third service data is acquired; The preset second time interval is greater than the preset first time interval.
5. The method according to claim 4, characterized in that The preset first time interval is 1 second, and the preset second time interval is 1 hour.
6. The method according to claim 4, characterized in that The method comprises: Using the MQTT communication protocol to establish a communication connection with a business device, the business device is used to provide the business data; Based on the communication connection, the first service data and / or the third service data are acquired from the service data provided by the service device.
7. A method for querying business data, characterized in that: The business data includes a plurality of business fields, and the business data is stored in a database using a business data storage method according to any one of claims 1 to 6, the method comprising: Receive data query requests; According to the data query request, query and output the fourth business data stored in the database; in, The value of each service field in the fourth service data is a valid value of each service field, and the valid value is a valid value last stored in the database before the third target time; The third target time is the time at which the data query request is received.
8. A storage device for business data, characterized in that: The service data includes a plurality of service fields, and the device includes: A first data acquisition module, configured to acquire first business data to be stored; A second data acquisition module is configured to acquire second business data stored in a database, wherein the value of each business field in the second business data is a valid value of each business field, and the valid value is a valid value last stored in the database before a first target time, and the first target time is the time when the first business data is acquired; A data comparison processing module, configured to compare the values of each business field in the first business data and the second business data; If the values of the business field in the first business data and the second business data are different, storing the value of the business field in the first business data as a valid value of the business field at the first target time in the database; If the value of the service field in the first service data is the same as that in the second service data, the value of the service field in the first service data is not stored in the database.
9. A device for querying business data, characterized in that: The business data includes a plurality of business fields, the business data is stored in a database using the business data storage method according to any one of claims 1 to 6, and the query device includes: A request receiving module, which is configured to receive a data query request; a data query module, configured to query and output fourth business data stored in the database according to the data query request; in, The value of each service field in the fourth service data is a valid value of each service field, and the valid value is a valid value last stored in the database before the third target time; The third target time is the time at which the data query request is received.
10. An electronic device, characterized in that: include: at least one processor; and, a memory communicatively coupled to the at least one processor; Wherein, a computer program is stored in the memory, and when the computer program is executed by the at least one processor, the business data storage method described in any one of claims 1 to 6 or the business data query method described in claim 7 is implemented.
11. A computer-readable storage medium storing a plurality of program codes, characterized in that: The program code is suitable for being loaded and run by a processor to execute the business data storage method described in any one of claims 1 to 6 or the business data query method described in claim 7.