Search

CN-122027664-A - Two-stage offline order data uploading method

CN122027664ACN 122027664 ACN122027664 ACN 122027664ACN-122027664-A

Abstract

The invention provides a two-stage offline order data uploading method, which belongs to the field of data synchronization and comprises the steps of S1, generating an order data record by a terminal device based on transaction data, S2, storing the order data record in a first-stage storage area, setting a state field, detecting a network connection state, initiating an uploading request to a cloud server when the network connection is normal, executing a transferring operation when the network connection is abnormal or the uploading is failed, S3, uploading the order data record in a second-stage storage area to the cloud server according to a preset time interval, deleting the order data record from the second-stage storage area if the uploading is successful, S4, judging whether the order data record is processed or not according to an order unique identifier, and returning a successful response to the terminal device if the order data record is processed. The invention realizes the self-adaptive optimization of the uploading strategy by the dynamic interval adjustment of the secondary storage area, and realizes the consideration of timeliness and reliability of data uploading.

Inventors

  • WANG PENG
  • LIN ZHE
  • CHEN CHEN

Assignees

  • 武汉利楚商务服务有限公司

Dates

Publication Date
20260512
Application Date
20260407

Claims (10)

  1. 1. A two-stage offline order data uploading method is characterized by comprising the following steps: s1, generating an order data record based on transaction data by a terminal device, wherein the order data record at least comprises service information and an order unique identifier; S2, storing the order data record in a primary storage area, setting a state field, and detecting the network connection state: when the network connection is normal, an uploading request is initiated to the cloud server, and when a successful response returned by the cloud server is received, a corresponding order data record is deleted from the primary storage area and the step S4 is entered; When the network connection is abnormal or the uploading fails, a transfer operation is executed, and the order data record is transferred from the primary storage area to the secondary storage area, wherein the primary storage area is used for uploading in real time, and the secondary storage area is used for continuously retrying; S3, uploading order data records in the secondary storage area to a cloud server according to a preset time interval, deleting the order data records from the secondary storage area and entering a step S4 when uploading is successful, and reserving the order data records to wait for the next time interval to be continuously uploaded when uploading is failed; S4, the cloud server extracts the order uniqueness mark in the order data record after receiving the uploading request, judges whether the order data record is processed according to the order uniqueness mark, returns a successful response to the terminal equipment if the order data record is processed, and returns a successful response to the terminal equipment after carrying out service processing on the order data record if the order data record is not processed.
  2. 2. The method for uploading two-stage offline order data as in claim 1, wherein said order unique identifier comprises a terminal device identifier, a time stamp and a serial number, wherein the time stamp is in millisecond precision, and the serial number is an incremental serial number maintained internally by the terminal device.
  3. 3. The method for uploading order data of two levels of offline order data as in claim 1, wherein said transferring order data record from primary storage area to secondary storage area comprises: updating a status field of the order data record in the primary storage area into a transfer state, and completely reserving the order data record in the primary storage area, wherein the status field comprises unprocessed, uploading state, transferring state, transferred state and completed state; reading the complete content of the order data record, writing the complete content into a secondary storage area, and recording a transfer time stamp; inquiring order data records in the secondary storage area according to the order uniqueness mark, and carrying out integrity check on the order data records in the primary storage area and the secondary storage area; the status field of the order data record in the primary storage area is updated to transferred when the integrity check passes, and remains in transfer when the integrity check fails.
  4. 4. The method for uploading two-stage offline order data as set forth in claim 3, wherein said integrity check comprises: reading order data record in the primary storage area and calculating hash value, and recording as ; Reading order data record in the secondary storage area and calculating hash value, and recording as ; Comparing hash values of order data records in primary storage area And hash value of order data record in secondary storage area : When (when) When the integrity check is passed, judging that the integrity check is passed; When (when) In the time-course of which the first and second contact surfaces, and judging that the integrity check is not passed.
  5. 5. The method for uploading two-stage offline order data as in claim 1, wherein step S2 further comprises a composite checking mechanism, comprising: Setting a sliding time window with preset duration, counting the uploading failure rate in real time in the sliding time window, and recording the last successful uploading time ; At the time of failure detection Calculating the uploading failure rate Sum and time difference The time difference For failure detection time And the last successful uploading time Time difference between; Failure rate when uploading Exceeding a preset failure rate threshold And time difference Exceeding a preset duration threshold In the time-course of which the first and second contact surfaces, judging that the network is in a continuous fault state; and stopping uploading the order data records of the primary storage area to the cloud server, and starting a transfer flow for the order data records in the primary storage area in batches.
  6. 6. A two-level offline order data uploading method according to claim 5, wherein said batch initiation transfer process is implemented by querying all status fields in the primary storage area for the uploaded order data records and performing transfer operations on these order data records piece by piece.
  7. 7. The method for uploading two-stage offline order data as in claim 6, wherein the method for calculating the upload failure rate comprises the following steps: Setting an uploading result queue with a fixed length, recording the uploading result and uploading time of each uploading operation to the end of the queue, wherein the uploading result is a successful or failed mark, and removing a history record that the uploading time is earlier than the starting time of the sliding time window; Calculating the number of times that the uploading result in the uploading result queue is failed And the total number of times in the queue To obtain the uploading failure rate ; Acquiring the uploading time corresponding to the record that the last uploading result in the uploading result queue is successful as the last successful uploading time If no record that the uploading result is successful exists, the starting time of the sliding time window is used as the last successful uploading time 。
  8. 8. The method for uploading two-stage offline order data as in claim 1, wherein the preset time interval in step S3 is a dynamically adjusted time interval, specifically comprising: Uploading task execution time Generating time from order data Calculating the time to live for each order data record in the secondary storage area ; According to survival time Dividing the order data record into a fresh order and a stale order, the fresh order being a time-to-live Less than a first time threshold The stale order is the survival time Greater than a second time threshold Wherein a first time threshold Less than a second time threshold ; Calculating the fresh order ratio respectively And stale order duty cycle ; Setting a history record queue, recording the uploading success rate of the uploading task of the latest preset times, and calculating the average uploading success rate ; Based on fresh order duty cycle Old order ratio And average upload success rate And adjusting the time interval triggered by the next uploading task.
  9. 9. A two-stage offline order data uploading method as in claim 8 wherein said fresh order based duty cycle Old order ratio And average upload success rate The time interval triggered by the next uploading task is adjusted, and the method specifically comprises the following steps: Setting a first duty ratio threshold A second duty cycle threshold First power threshold And a second power threshold Wherein the first duty cycle threshold Less than a second duty cycle threshold First power threshold Less than a second power threshold ; When the fresh order is in proportion to And average upload success rate When calculating the time interval of the next trigger : ; Wherein the method comprises the steps of For the current time interval of the time period, Is a first adjustment coefficient and , Is a preset maximum spacing limit; When the stale order is in proportion to When calculating the time interval of the next trigger : ; Wherein the method comprises the steps of Is of a second adjustment coefficient and , Is a preset minimum interval limit; When the fresh order is in proportion to And stale order duty cycle If the average uploading success rate is the same The time interval for the next trigger is calculated: ; Wherein the method comprises the steps of Is a third adjustment coefficient and ; If average uploading success rate Then the current time interval is kept unchanged ; If average uploading success rate The time interval for the next trigger is calculated: ; Wherein the method comprises the steps of Is a fourth adjustment coefficient and 。
  10. 10. The method for uploading two-stage offline order data as in claim 3, wherein step S2 further comprises a background cleaning task, specifically comprising: triggering a cleaning task according to a preset time interval or when the number of order data records with the state field in the primary storage area being the transferred state exceeds a preset number threshold; inquiring order data records with all status fields in a primary storage area being transferred status to form a list to be cleaned; Traversing the list to be cleaned, and inquiring whether corresponding order data records exist in the secondary storage area according to the order uniqueness mark for each order data record; The order data record is deleted from the primary storage area when the corresponding order data record is queried in the secondary storage area, and the status field of the order data record is rolled back to the in-transition status when the corresponding order data record is not queried.

Description

Two-stage offline order data uploading method Technical Field The invention relates to the technical field of data synchronization, in particular to a two-stage offline order data uploading method. Background In application scenarios such as mobile payment and offline transaction, the terminal device needs to upload order data to the cloud server, but the uploading is often failed due to instability of the network environment. The existing offline data synchronization scheme generally adopts a strategy of locally storing and timing synchronization, but the technical problems of the scheme are that firstly, a precise identification mechanism for continuous network faults is lacked, instantaneous network faults and continuous network faults cannot be distinguished, or a large amount of invalid retries are performed to waste system resources when the continuous network faults occur, or the retries are too conservatively reduced to reduce the number of times of the retries, so that timeliness of data uploading is reduced, secondly, the timing synchronization adopts a fixed time interval strategy, uploading frequency cannot be dynamically adjusted according to network states and order timeliness distribution, resource waste is caused when the network conditions are poor, and the order backlog cannot be timely cleaned. The conventional transfer operation generally adopts a simple flow of writing before deleting, and source data is deleted immediately after writing is completed, so that the method cannot be restored to a consistent state when interruption occurs in the transfer process, and whether the transfer is really completed or not cannot be judged, and potential hazards of data reliability exist. Chinese patent CN103491162a discloses an information sharing method based on mobile internet, which directly displays the information to be uploaded on a local terminal after receiving the information to be uploaded, meanwhile submits the information to be uploaded to a pre-established information uploading queue, and uploads the information to be uploaded to a server according to a predetermined sequence by the information uploading queue, and when detecting that the network state is good or a timing point is triggered, continues uploading until the information uploading is successful. However, when the network is unstable, the network state cannot be recognized in time and the strategy adjustment is carried out on the data uploading, so that the data volume is not uploaded in time and the data is lost. Disclosure of Invention In view of the above, the invention provides a two-stage offline order data uploading method, which solves the problem that the data cannot be uploaded timely and accurately when the network is unstable in the prior art, realizes the self-adaptive optimization of uploading strategies through dynamic interval adjustment of a two-stage storage area, ensures the timely uploading of the order data and the data not to be lost in the unstable network environment, and simultaneously effectively reduces the resource consumption under the condition of network fluctuation. The technical scheme of the invention is realized in such a way that the invention provides a two-stage offline order data uploading method, which comprises the following steps: s1, generating an order data record based on transaction data by a terminal device, wherein the order data record at least comprises service information and an order unique identifier; S2, storing the order data record in a primary storage area, setting a state field, and detecting the network connection state: when the network connection is normal, an uploading request is initiated to the cloud server, and when a successful response returned by the cloud server is received, a corresponding order data record is deleted from the primary storage area and the step S4 is entered; When the network connection is abnormal or the uploading fails, a transfer operation is executed, and the order data record is transferred from the primary storage area to the secondary storage area, wherein the primary storage area is used for uploading in real time, and the secondary storage area is used for continuously retrying; S3, uploading order data records in the secondary storage area to a cloud server according to a preset time interval, deleting the order data records from the secondary storage area and entering a step S4 when uploading is successful, and reserving the order data records to wait for the next time interval to be continuously uploaded when uploading is failed; S4, the cloud server extracts the order uniqueness mark in the order data record after receiving the uploading request, judges whether the order data record is processed according to the order uniqueness mark, returns a successful response to the terminal equipment if the order data record is processed, and returns a successful response to the terminal equipment after carrying out service processing on t