CN-121073510-B - Block chain-based food tracing method and system
Abstract
The invention relates to the technical field of blockchain food tracing, and discloses a blockchain-based food tracing method and a blockchain-based food tracing system, wherein the blockchain-based food tracing method and the blockchain-based food tracing system comprise the steps of performing timestamp processing on batch numbers, production dates, transportation temperatures and storage humidity, and calculating dynamic shelf life to generate tracing records; the method comprises the steps of encrypting a batch number and a dynamic shelf life to generate a tamper-proof hash value, generating a food state record by combining the hash value when the temperature and humidity exceed a threshold value, synchronizing the food state record to a supply chain link point and performing consistency verification to obtain a shared data set, generating a trusted two-dimensional code containing the batch number, the dynamic shelf life and a circulation record based on the shared data set, performing verification after a consumer scans the code, extracting a shelf life field and a circulation information abstract, comparing the dynamic shelf life with the current time to generate a user interface, extracting consumer feedback and verifying batch matching through a timestamp, and generating a food tracing report. The invention can reflect the food state in real time, prevent data tampering and improve the traceability.
Inventors
- WANG XIAOBO
- QI MING
- CHEN BINGBING
- ZHENG PEIJUN
- LIAO JIELIANG
- DENG YANFEN
Assignees
- 佛山职业技术学院
- 佛山市顺德区屏荣食品发展有限公司
Dates
- Publication Date
- 20260505
- Application Date
- 20251106
Claims (8)
- 1. A blockchain-based food tracing method, comprising: Acquiring batch numbers, production dates, transportation temperatures and storage humidity of foods, performing blockchain timestamp processing, generating food processing data, calculating a dynamic shelf life according to a preset shelf life calculation rule, and combining the food processing data and the dynamic shelf life to form a food traceability record; Encrypting the batch numbers and the dynamic shelf lives in the food tracing records by adopting an SHA-256 algorithm to generate tamper-proof hash values; when the transportation temperature in the food tracing record is greater than a preset temperature threshold value or the stored humidity data is greater than a preset humidity threshold value, the dynamic shelf life is updated in combination with the tamper-resistant hash value, and a new tamper-resistant hash value is generated by encryption, so that a food state record is obtained; Synchronizing the food state records to each supply chain node, and judging consistency of batch numbers and shelf lives to obtain a shared food state data set; generating a trusted two-dimensional code comprising a batch number, a dynamic shelf life and a circulation record according to the shared food state data set to obtain a two-dimensional code image for scanning by a consumer; If the consumer scans and inquires the two-dimensional code image, performing validity and integrity comparison according to the shared food state data set to obtain a shelf life field and a circulation information abstract; comparing the dynamic shelf life with the current time according to the shelf life field and the circulation information abstract, determining whether the food is in a valid period state, and combining the valid period state, the shelf life field and the circulation information abstract to generate a user interaction interface; Extracting consumer feedback evaluation according to the user interaction interface, and checking batch matching by combining with a preset time stamp to obtain a trusted feedback record; Updating the shared food state data set according to the trusted feedback record and synchronizing the shared food state data set to each supply chain node to generate a final food traceability report containing batch numbers and circulation information summaries; When the transportation temperature in the food tracing record is greater than a preset temperature threshold or the stored humidity data is greater than a preset humidity threshold, the dynamic shelf life is updated in combination with the tamper-proof hash value and a new tamper-proof hash value is generated by encryption, so that a food state record is obtained, and the method comprises the following steps: Generating an environment abnormality mark when the transportation temperature in the food tracing record is greater than a preset temperature threshold or the stored humidity data is greater than a preset humidity threshold; Correcting the dynamic shelf life according to the environment anomaly marks and the tamper-proof hash value, and encrypting the batch number and the corrected dynamic shelf life by adopting an SHA-256 algorithm to generate a new tamper-proof hash value to form an updated food state record; wherein, the preset shelf life adjustment rule includes: The system can dynamically fine-tune the deduction coefficient based on historical quality detection data, and in long-term operation, the system can accumulate a large number of batches of environmental data and actual quality guarantee period detection results and correct the environmental data and the actual quality guarantee period detection results through a statistical analysis or modeling method, wherein one implementation mode is to adopt a linear regression model, take the temperature exceeding amplitude, the humidity exceeding amplitude and the exceeding duration as independent variables, take the actual quality guarantee period shortening days as dependent variables and fit new deduction coefficient, and the other implementation mode is to automatically learn the nonlinear relation between the environmental parameters and the quality guarantee period shortening by utilizing a machine learning algorithm, so that the correction rule is dynamically optimized under different seasons and different food types; Wherein the performing validity and integrity comparisons from the shared food status dataset comprises: The system compares the validity of the extracted timestamp field, wherein the timestamp is a time mark automatically generated when the food tracing record is written into the blockchain and is used for representing the generation time and the storage sequence of the record, in the comparison process, the system calculates the difference value between the timestamp and the current system time and judges whether the difference value is within a preset allowable time limit range, if the difference value exceeds the preset allowable time limit range, the data is judged to be possibly out of date or have synchronous abnormality, and the subsequent display operation is stopped.
- 2. The blockchain-based food tracing method of claim 1, wherein encrypting the lot number and the dynamic shelf life in the food tracing record using SHA-256 algorithm to generate the tamper-resistant hash value comprises: According to the batch number and the dynamic shelf life in the food tracing record, performing encryption operation by adopting an SHA-256 algorithm to generate a first hash value; writing the first hash value and the food tracing record into a preset blockchain distributed account book together, so that the first hash value is distributed and stored among a plurality of nodes; invoking the food tracing record from the preset blockchain distributed ledger, and re-adopting an SHA-256 algorithm to carry out encryption operation on the batch number and the dynamic shelf life to generate a second hash value; and when the second hash value is equal to the first hash value, determining the second hash value as a tamper-proof hash value.
- 3. The blockchain-based food tracing method of claim 1, wherein synchronizing the food status records to supply chain nodes and determining lot number and shelf life consistency results in a shared food status dataset comprises: Carrying out distributed synchronization on the food state records according to preset supply chain link point identifiers to form a synchronization state data set of each supply chain node; generating hash values for batch numbers and dynamic shelf lives in the synchronous state data set, comparing the batch numbers and the dynamic shelf lives among the supply chain nodes, and determining that consistency verification passes when the hash values of the supply chain nodes are consistent to obtain a consistency verification result; And recording the consistency check result to a preset blockchain distributed ledger to form a shared food state data set which can be called later.
- 4. The blockchain-based food tracing method of claim 1, wherein the generating a trusted two-dimensional code including a lot number, a dynamic shelf life, and a circulation record according to the shared food status dataset, to obtain a two-dimensional code image for scanning by a consumer, comprises: Analyzing the shared food state data set into structured food information data, and associating a dynamic shelf life and a circulation record by taking a batch number as a main key; Generating a real-time information character string according to the structured food information data; Calling a data encryption key from a preset key library, and encrypting the real-time information character string to obtain an encrypted information character string; and encoding the encrypted information character string into a two-dimensional code to obtain a two-dimensional code image for scanning by a consumer.
- 5. The blockchain-based food tracing method of claim 1, wherein if the consumer scans and inquires the two-dimensional code image, performing validity and integrity comparison according to the shared food status dataset to obtain a shelf life field and a circulation information summary, comprising: If the consumer scans and inquires the two-dimensional code image, analyzing the two-dimensional code image to obtain an encrypted information character string, and decrypting the encrypted information character string by combining a preset decryption module and extracting the number of the food batch; calling a corresponding sharing record in the sharing food state data set according to the food batch number; performing validity comparison on the timestamp field in the shared record, and confirming that the data generation time is within a preset permission time limit; carrying out integrity comparison on the hash value field in the shared record, and confirming that the record is not tampered; And outputting the quality guarantee period field and the circulation information abstract under the condition that the time stamp and the hash value pass verification.
- 6. The blockchain-based food tracing method of claim 1, wherein the comparing the dynamic shelf life with the current time according to the shelf life field and the circulation information abstract, determining whether the food is in a valid state, and combining the valid state, the shelf life field and the circulation information abstract to generate a user interaction interface comprises: Comparing the current time of the dynamic shelf life to determine whether the food is within the effective period; when the food is in the valid period, combining the valid period state, the quality guarantee period field and the circulation information abstract into state data; And converting the state data into interface display elements to generate the user interaction interface.
- 7. The blockchain-based food tracing method of claim 5, wherein the extracting consumer feedback evaluation and verifying batch matching in combination with a preset timestamp according to the user interaction interface to obtain a trusted feedback record, and generating a final food tracing report according to the trusted feedback record comprises: sorting consumer scoring and comment data in the user interaction interface into structured feedback records, and generating evaluation data based on the structured feedback records and the food batch numbers; adding a preset time stamp to the evaluation data and binding to the food batch number to form constraint evaluation data with the time stamp; when the batch number of the constraint evaluation data is consistent with the preset food batch number, generating a trusted feedback record; integrating the trusted feedback record with the batch number and circulation information in the shared food state dataset to generate an updated traceable dataset; synchronizing the traceable data set to a supply chain node, and carrying out consistency comparison on the synchronized node data; and under the condition that the consistency comparison is passed, generating a final food traceability report containing the batch number and the circulation information abstract.
- 8. A blockchain-based food tracing system for implementing the blockchain-based food tracing method of any of claims 1 to 7, comprising: The data acquisition module is used for acquiring batch numbers, production dates, transportation temperatures and storage humidity of foods, performing blockchain timestamp processing to generate food processing data, calculating a dynamic shelf life according to a preset shelf life calculation rule, and combining the food processing data and the dynamic shelf life to form a food traceability record; The encryption generation module is used for encrypting the batch numbers and the dynamic shelf lives in the food tracing records by adopting an SHA-256 algorithm to generate tamper-proof hash values; The food state module is used for updating the dynamic shelf life by combining the tamper-proof hash value and encrypting to generate a new tamper-proof hash value when the transportation temperature in the food tracing record is greater than a preset temperature threshold or the stored humidity data is greater than a preset humidity threshold, so as to obtain a food state record; the shared data module is used for synchronizing the food state records to all supply chain nodes, judging consistency of batch numbers and shelf lives and obtaining a shared food state data set; the data synthesis module is used for generating a trusted two-dimensional code comprising a batch number, a dynamic shelf life and a circulation record according to the shared food state data set to obtain a two-dimensional code image for a consumer to scan; The state verification module is used for executing validity and integrity comparison according to the shared food state data set if the consumer scans and inquires the two-dimensional code image to obtain a shelf life field and a circulation information abstract; The user interaction module is used for comparing the dynamic shelf life with the current time according to the shelf life field and the circulation information abstract, determining whether the food is in a valid period state or not, and combining the valid period state, the shelf life field and the circulation information abstract to generate a user interaction interface; The trusted feedback module is used for extracting consumer feedback evaluation according to the user interaction interface and checking batch matching by combining with a preset time stamp to obtain a trusted feedback record; and the food tracing module is used for updating the shared food state data set according to the trusted feedback record and synchronizing the shared food state data set to each supply chain node to generate a final food tracing report containing batch numbers and circulation information summaries.
Description
Block chain-based food tracing method and system Technical Field The invention relates to the technical field of block chain food tracing, in particular to a block chain-based food tracing method and system. Background At present, food tracing plays an important role in guaranteeing food safety and improving consumer trust, and is characterized in that the traceability of the whole process from production to consumption of food is realized through the transparency of supply chain information so as to ensure quality and safety. However, in practical application, because of numerous supply chain participants and complex data sources, the traditional tracing method generally relies on a centralized database, so that information is difficult to share in real time among different links, thereby causing the breakage of upstream and downstream information of the supply chain, and the state of food in each link of production, transportation and sales cannot be comprehensively reflected. In one prior art, a part of the system records food batch information, production date and transportation data through a centralized management platform, and provides two-dimensional code query service for consumers. After scanning the two-dimension code, the consumer can check basic traceability information of the food, such as manufacturers and main transportation nodes. However, the method generally records only the initial quality guarantee period and the fixed circulation information, and lacks real-time tracking and synchronization of dynamic change states (such as quality guarantee period shortening caused by temperature abnormality) in the transportation and storage processes, so that the traceable data cannot accurately reflect the actual conditions of foods in the circulation process. The prior art has the problems of information island and inconsistent data, and is difficult to ensure the credibility and real time of the data under the participation of multiple parties, so that consumers cannot acquire real food state information in time. Disclosure of Invention The invention provides a food tracing method and a system based on a block chain, which are used for solving the problem of inconsistent information island and data in the prior art and realizing real-time credible tracing of food states. In order to solve the technical problems, the present invention provides a blockchain-based food tracing method, which includes: Acquiring batch numbers, production dates, transportation temperatures and storage humidity of foods, performing blockchain timestamp processing, generating food processing data, calculating a dynamic shelf life according to a preset shelf life calculation rule, and combining the food processing data and the dynamic shelf life to form a food traceability record; Encrypting the batch numbers and the dynamic shelf lives in the food tracing records by adopting an SHA-256 algorithm to generate tamper-proof hash values; when the transportation temperature in the food tracing record is greater than a preset temperature threshold value or the stored humidity data is greater than a preset humidity threshold value, the dynamic shelf life is updated in combination with the tamper-resistant hash value, and a new tamper-resistant hash value is generated by encryption, so that a food state record is obtained; Synchronizing the food state records to each supply chain node, and judging consistency of batch numbers and shelf lives to obtain a shared food state data set; generating a trusted two-dimensional code comprising a batch number, a dynamic shelf life and a circulation record according to the shared food state data set to obtain a two-dimensional code image for scanning by a consumer; If the consumer scans and inquires the two-dimensional code image, performing validity and integrity comparison according to the shared food state data set to obtain a shelf life field and a circulation information abstract; comparing the dynamic shelf life with the current time according to the shelf life field and the circulation information abstract, determining whether the food is in a valid period state, and combining the valid period state, the shelf life field and the circulation information abstract to generate a user interaction interface; Extracting consumer feedback evaluation according to the user interaction interface, and checking batch matching by combining with a preset time stamp to obtain a trusted feedback record; And updating the shared food state data set according to the trusted feedback record and synchronizing the shared food state data set to each supply chain node to generate a final food traceability report containing batch numbers and circulation information summaries. In a second aspect, the present invention provides a blockchain-based food traceability system comprising: the method comprises the steps that a data acquisition module acquires batch numbers, production dates, transportation temperatures