CN117611269A - Inventory deduction method and device - Google Patents

Inventory deduction method and device Download PDF

Info

Publication number
CN117611269A
CN117611269A CN202311370761.1A CN202311370761A CN117611269A CN 117611269 A CN117611269 A CN 117611269A CN 202311370761 A CN202311370761 A CN 202311370761A CN 117611269 A CN117611269 A CN 117611269A
Authority
CN
China
Prior art keywords
commodity
inventory
commodities
request
locking
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202311370761.1A
Other languages
Chinese (zh)
Inventor
汤定一
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Zhoupu Data Technology Nanjing Co ltd
Original Assignee
Zhoupu Data Technology Nanjing Co ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Zhoupu Data Technology Nanjing Co ltd filed Critical Zhoupu Data Technology Nanjing Co ltd
Priority to CN202311370761.1A priority Critical patent/CN117611269A/en
Publication of CN117611269A publication Critical patent/CN117611269A/en
Pending legal-status Critical Current

Links

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06QINFORMATION AND COMMUNICATION TECHNOLOGY [ICT] SPECIALLY ADAPTED FOR ADMINISTRATIVE, COMMERCIAL, FINANCIAL, MANAGERIAL OR SUPERVISORY PURPOSES; SYSTEMS OR METHODS SPECIALLY ADAPTED FOR ADMINISTRATIVE, COMMERCIAL, FINANCIAL, MANAGERIAL OR SUPERVISORY PURPOSES, NOT OTHERWISE PROVIDED FOR
    • G06Q30/00Commerce
    • G06Q30/06Buying, selling or leasing transactions
    • G06Q30/0601Electronic shopping [e-shopping]
    • G06Q30/0633Lists, e.g. purchase orders, compilation or processing
    • G06Q30/0635Processing of requisition or of purchase orders
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/23Updating
    • G06F16/2308Concurrency control
    • G06F16/2336Pessimistic concurrency control approaches, e.g. locking or multiple versions without time stamps
    • G06F16/2343Locking methods, e.g. distributed locking or locking implementation details
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/25Integrating or interfacing systems involving database management systems
    • G06F16/252Integrating or interfacing systems involving database management systems between a Database Management System and a front-end application
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06QINFORMATION AND COMMUNICATION TECHNOLOGY [ICT] SPECIALLY ADAPTED FOR ADMINISTRATIVE, COMMERCIAL, FINANCIAL, MANAGERIAL OR SUPERVISORY PURPOSES; SYSTEMS OR METHODS SPECIALLY ADAPTED FOR ADMINISTRATIVE, COMMERCIAL, FINANCIAL, MANAGERIAL OR SUPERVISORY PURPOSES, NOT OTHERWISE PROVIDED FOR
    • G06Q10/00Administration; Management
    • G06Q10/08Logistics, e.g. warehousing, loading or distribution; Inventory or stock management
    • G06Q10/087Inventory or stock management, e.g. order filling, procurement or balancing against orders

Landscapes

  • Engineering & Computer Science (AREA)
  • Business, Economics & Management (AREA)
  • Theoretical Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Databases & Information Systems (AREA)
  • Physics & Mathematics (AREA)
  • Accounting & Taxation (AREA)
  • Finance (AREA)
  • Economics (AREA)
  • Marketing (AREA)
  • General Business, Economics & Management (AREA)
  • Strategic Management (AREA)
  • Data Mining & Analysis (AREA)
  • Development Economics (AREA)
  • General Engineering & Computer Science (AREA)
  • Entrepreneurship & Innovation (AREA)
  • Human Resources & Organizations (AREA)
  • Operations Research (AREA)
  • Quality & Reliability (AREA)
  • Tourism & Hospitality (AREA)
  • Management, Administration, Business Operations System, And Electronic Commerce (AREA)

Abstract

The invention provides a stock deduction method and a device, which relate to the technical field of Internet, wherein the stock deduction method comprises the following steps: receiving order request data sent by a user side terminal, wherein the order request data comprises commodity data of a plurality of commodities, and the commodity data comprises commodity IDs; generating a locking request according to the order request data, wherein the locking request contains all the IDs of the commodities to be locked; sending a locking request to the distributed lock service so that the distributed lock service locks all the IDs of the commodities to be locked; when a locking success prompt returned by the distributed lock service is received, carrying out inventory deduction on all commodities; after inventory deduction is successfully carried out on all commodities, an unlocking request is sent to the distributed lock service, so that the distributed lock service can unlock all the commodity IDs to be unlocked, and the unlocking request contains all the commodity IDs to be unlocked. The invention can reduce the pressure of the distributed lock service and improve the processing efficiency of orders.

Description

Inventory deduction method and device
Technical Field
The invention relates to the technical field of Internet, in particular to an inventory deduction method and device.
Background
In SaaS (Software-as-a-Service) applications of the in-Service and out-of-stock scenario, order Service and inventory Service are necessary functions. Since there is often concurrency when an order contains a very large number of products (e.g., hundreds of products), when inventory is deducted from the order products, the inventory products need to be locked to avoid overstocking due to concurrency.
The prior method for deducting the inventory of the commodity comprises the following steps: and traversing the commodity list of the order for any order, and calling a distributed lock service for each commodity resource in the order to lock the commodity resource. And then, after deducting all commodity inventory in the order, sequentially calling a distributed lock service for each commodity resource in the order to unlock the commodity resource.
However, in the above scheme, there are problems that the pressure of the distributed lock service is large and the order processing efficiency is slow.
Disclosure of Invention
The invention provides a stock deduction method and a device for solving the problems of high pressure and low order processing efficiency of distributed lock service in the prior art.
The technical scheme of the invention is as follows:
the invention provides an inventory deduction method, which comprises the following steps:
receiving order request data sent by a user side terminal, wherein the order request data comprises commodity data of a plurality of commodities, and the commodity data comprises commodity IDs;
generating a locking request according to the order request data, wherein the locking request contains all the IDs of the commodities to be locked;
sending the locking request to a distributed lock service so that the distributed lock service locks all the to-be-locked commodity IDs;
when a locking success prompt returned by the distributed lock service is received, carrying out inventory deduction on all commodities;
and after the inventory deduction is successfully carried out on all the commodities, an unlocking request is sent to the distributed lock service so that the distributed lock service can unlock all the commodity IDs to be unlocked, and the unlocking request contains all the commodity IDs to be unlocked.
Optionally, generating a locking request according to the order request data specifically includes:
analyzing the order request data to obtain commodity IDs of all the commodities;
duplicate removal of commodity IDs of all the commodities;
and generating the locking request according to the duplicate commodity ID after duplicate removal, wherein the locking request comprises the duplicate commodity ID after duplicate removal.
Optionally, after sending the locking request to the distributed lock service, the present stock deduction method further includes:
if the locking success prompt returned by the distributed lock service is not received within the time period of the first preset time period from the sending of the locking request, the step of sending the locking request to the distributed lock service is executed until the time period for waiting for the locking success prompt reaches the second preset time period, and if the locking success prompt returned by the distributed lock service is still not received, the locking failure is determined.
Optionally, the stock deduction method further includes:
for any to-be-locked commodity ID, if the distributed lock service does not receive the unlocking request within a time period of a third preset duration from the time of completing locking of the to-be-locked commodity ID, the distributed lock service automatically unlocks the to-be-locked commodity ID.
Optionally, the distributed lock service is a dis Cluster, and the distributed lock service uses Lua script.
Optionally, inventory deduction is performed on all the commodities, which specifically includes:
sending an inventory inquiry request to a commodity inventory database, wherein the inventory inquiry request comprises commodity IDs of all commodities;
receiving commodity inventory data returned by the commodity inventory database, wherein the commodity inventory data comprises inventory numbers of all commodities;
performing inventory analysis according to the commodity inventory data and commodity purchase quantity of all commodities, wherein the commodity data further comprises commodity purchase quantity;
if the analysis result shows that the inventory-deficient commodity exists, generating a commodity inventory-deficient prompt;
if the analysis result shows that the inventory-deficient commodities do not exist, calculating the remaining quantity of all the commodities after inventory deduction according to the commodity inventory data and the commodity purchase quantity of all the commodities;
generating an inventory update request according to the residual quantity after inventory deduction of all the commodities;
and sending the inventory updating request to the commodity inventory database so that the commodity inventory database updates the inventory quantity of all the commodities.
Optionally, according to the commodity inventory data and the commodity purchase quantity of all the commodities, performing inventory analysis specifically includes:
taking each commodity as a target commodity one by one, and executing the following steps:
determining the stock quantity of the target commodity according to the commodity stock data;
determining the commodity purchase quantity of the target commodity according to the commodity purchase quantity of all the commodities;
judging whether the stock quantity of the target commodity is smaller than the commodity purchase quantity of the target commodity;
if the stock quantity of the target commodity is smaller than the commodity purchase quantity of the target commodity, determining that the stock of the target commodity is insufficient;
and if the stock quantity of the target commodity is not less than the commodity purchase quantity of the target commodity, determining that the stock of the target commodity is sufficient.
Optionally, the stock deduction method further includes:
and when the inventory shortage of any commodity is determined for the first time, ending the inventory analysis.
The invention also provides an inventory deduction device, which comprises:
the order receiving data module is used for receiving order request data sent by the user side terminal, wherein the order request data comprises commodity data of a plurality of commodities, and the commodity data comprises commodity IDs;
the locking request generation module is used for generating a locking request according to the order request data, wherein the locking request comprises all the to-be-locked commodity IDs;
the locking module is used for sending the locking request to a distributed locking service so that the distributed locking service locks all the to-be-locked commodity IDs;
the inventory deduction module is used for performing inventory deduction on all the commodities when receiving a locking success prompt returned by the distributed lock service;
and the unlocking module is used for sending an unlocking request to the distributed lock service after the inventory deduction is successfully carried out on all the commodities so as to enable the distributed lock service to unlock all the commodity IDs to be unlocked, wherein the unlocking request comprises all the commodity IDs to be unlocked.
Optionally, the inventory deduction module is specifically configured to:
sending an inventory inquiry request to a commodity inventory database, wherein the inventory inquiry request comprises commodity IDs of all commodities;
receiving commodity inventory data returned by the commodity inventory database, wherein the commodity inventory data comprises inventory numbers of all commodities;
performing inventory analysis according to the commodity inventory data and commodity purchase quantity of all commodities, wherein the commodity data further comprises commodity purchase quantity;
if the analysis result shows that the inventory-deficient commodity exists, generating a commodity inventory-deficient prompt;
if the analysis result shows that the inventory-deficient commodities do not exist, calculating the remaining quantity of all the commodities after inventory deduction according to the commodity inventory data and the commodity purchase quantity of all the commodities;
generating an inventory update request according to the residual quantity after inventory deduction of all the commodities;
and sending the inventory updating request to the commodity inventory database so that the commodity inventory database updates the inventory quantity of all the commodities.
The invention adopts the technical scheme and has the following beneficial effects:
according to the inventory deduction method, all the commodity IDs to be locked are sent to the distributed locking service at one time, so that the distributed locking service locks all the commodity IDs to be locked in batches, namely, when all the commodity IDs to be locked are locked, the distributed locking service is only required to be called once; in the same way, the invention only needs to call the distributed lock service once when the batch unlocking is carried out on all the commodity IDs to be unlocked. The invention reduces the interaction times with the distributed lock service, reduces the access pressure of the distributed lock service, reduces the influence of network delay on locking and unlocking time, further improves the locking and unlocking efficiency of orders, and improves the processing efficiency of orders.
Drawings
In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings that are required to be used in the embodiments or the description of the prior art will be briefly described below, and it is obvious that the drawings in the following description are only embodiments of the present invention, and that other drawings can be obtained according to the provided drawings without inventive effort for a person skilled in the art.
FIG. 1 is a schematic flow chart of a method for inventory deduction according to an embodiment of the present invention;
FIG. 2 is a flow chart of another inventory deduction method according to an embodiment of the present invention;
fig. 3 is a schematic structural diagram of an inventory deduction device according to an embodiment of the present invention.
Detailed Description
The following description of the embodiments of the present invention will be made clearly and completely with reference to the accompanying drawings, in which it is apparent that the embodiments described are only some embodiments of the present invention, but not all embodiments. All other embodiments, which can be made by those skilled in the art based on the embodiments of the invention without making any inventive effort, are intended to be within the scope of the invention.
In SaaS applications in the purchase, sale, and inventory scenario, order service and inventory service are necessary functions. Since there is often concurrency when an order contains a lot of goods, when the order goods are deducted from stock, the stock goods need to be locked to avoid the phenomenon of overstocking of goods due to concurrency.
The prior method for deducting the inventory of the commodity comprises the following steps: and traversing the commodity list of the order for any order, and calling a distributed lock service for each commodity resource in the order to lock the commodity resource. And then, after deducting all commodity inventory in the order, sequentially calling a distributed lock service for each commodity resource in the order to unlock the commodity resource.
However, in the above scheme, when each commodity resource is locked or unlocked, the distributed lock service needs to be invoked, so that the access pressure of the distributed lock service is larger, the influence of network delay on the locking or unlocking time is larger, further, the locking and unlocking time of orders is longer, the probability of lock conflict between different orders is also increased, and the processing efficiency of orders is reduced. When the multiple orders contain the same commodity, the distributed lock service needs to lock the commodity in the multiple orders in sequence, and in the process, the orders are in a state of waiting for locking, namely, the locking conflict occurs.
Based on the above, in order to reduce the pressure of distributed lock service and improve the processing efficiency of orders, the invention provides a stock deduction method and a device.
The technical scheme of the invention is described in detail below with reference to the accompanying drawings.
Fig. 1 is a schematic flow chart of a stock deduction method according to an embodiment of the present invention. The inventory deduction method is applied to the SaaS application service, wherein the SaaS application service comprises order service and inventory service.
As shown in fig. 1, the present stock deduction method includes:
step 101: order request data sent by a user side terminal is received, the order request data comprises commodity data of a plurality of commodities, and the commodity data comprises commodity IDs.
Specifically, the user terminal may be a computer or a smart phone. After logging in the online commodity selling platform through the user terminal, the user selects commodities to be purchased online and submits orders. After the user submits the order, the user terminal generates and transmits order request data.
Step 102: and generating a locking request according to the order request data, wherein the locking request contains all the to-be-locked commodity IDs.
In the embodiment of the present invention, step 102: generating a locking request according to the order request data may specifically include:
(1) And analyzing the order request data to obtain the commodity IDs of all the commodities.
(2) And randomly arranging the commodity IDs of all commodities to obtain a locking request.
In one specific example, the order request data displays that the items purchased by the user are: and analyzing the order request data to obtain commodity IDs of all commodities, wherein the commodity IDs are as follows: 001. 001 and 002, wherein the ID of the A mineral water is 001 and the ID of the B mineral water is 002. Finally, commodity IDs of all commodities are arranged randomly, and the arrangement result is assumed to be: 001. 001, 002, i.e. the locking request is: 001. 001, 002.
In the embodiment of the present invention, step 102: generating a locking request according to the order request data may specifically further include:
(1) And analyzing the order request data to obtain the commodity IDs of all the commodities.
(2) The commodity IDs of all commodities are deduplicated.
Specifically, the hash values of the commodity IDs of all the commodities may be calculated here, then, the commodity IDs with the same hash value are determined to be the same commodity ID, and duplicate commodity IDs are deduplicated.
(3) And generating a locking request according to the duplicate product ID after duplicate removal, wherein the locking request contains the duplicate product ID after duplicate removal.
Following the foregoing example, the order request data displays that the items purchased by the user are: and analyzing the order request data to obtain commodity IDs of all commodities, wherein the commodity IDs are as follows: 001. 001 and 002, and then, after the duplication removal of the commodity IDs of all the commodities, obtaining duplicated commodity IDs as: 001 and 002. Finally, the locking requests are determined to be 001 and 002. Therefore, compared with the scheme of not carrying out the duplication removal on the commodity ID, in the scheme, only one time of locking and unlocking is needed to be carried out on 001, and in the scheme of not carrying out the duplication removal on the commodity ID, two times of locking and unlocking are needed to be carried out on 001. Therefore, the scheme can reduce locking and unlocking times.
Step 103: and sending a locking request to the distributed lock service so that the distributed lock service locks all the to-be-locked commodity IDs.
Specifically, in the distributed system, redis Cluster is selected as the distributed lock service, and the distributed lock service uses Lua script to ensure atomicity under the concurrency scene. When locking each commodity ID in the locking request, calling the script function of the Redis Cluster, and transmitting each commodity ID in the locking request to the Redis Cluster so that the Redis Cluster uses SETNX (SET if Not eXists) command to lock each commodity ID one by one in the first Lua script according to the commodity ID sequence displayed by the locking request.
Step 104: and when a locking success prompt returned by the distributed lock service is received, inventory deduction is carried out on all commodities.
Step 105: after inventory deduction is successfully carried out on all commodities, an unlocking request is sent to the distributed lock service, so that the distributed lock service can unlock all the commodity IDs to be unlocked, and the unlocking request contains all the commodity IDs to be unlocked.
Specifically, after inventory deduction is successfully performed on all commodities, an unlocking request containing the IDs of the commodities to be unlocked is generated, and the unlocking request is sent to the distributed lock service, so that the distributed lock service uses the second Lua script to unlock the IDs of the commodities to be unlocked.
By adopting the technical scheme, the inventory deduction method of the invention can send all the to-be-locked commodity IDs to the distributed lock service at one time, so that the distributed lock service can lock all the to-be-locked commodity IDs in batches, namely, when all the to-be-locked commodity IDs are locked, only one distributed lock service is required to be called; in the same way, the invention only needs to call the distributed lock service once when the batch unlocking is carried out on all the commodity IDs to be unlocked. The invention reduces the access pressure of the distributed lock service, reduces the influence of network delay on locking and unlocking time, further shortens the locking and unlocking time of orders, reduces the probability of lock conflict between different orders, and improves the processing efficiency of orders.
In the embodiment of the present invention, after sending a locking request to a distributed lock service, the inventory deduction method of the present invention may further include:
if a successful locking prompt returned by the distributed lock service is not received within a first preset time period from the sending of the locking request, executing the step of sending the locking request to the distributed lock service until the accumulated time waiting for the successful locking prompt reaches a second preset time period, and if the successful locking prompt returned by the distributed lock service is still not received, determining that the locking is failed and generating a locking failure prompt.
In a specific example, assume that the first preset duration is equal to 100 milliseconds and the second preset duration is equal to 10 seconds. After the locking request is sent to the distributed lock service, starting to wait for the distributed lock service to return a locking success prompt, if the locking success prompt returned by the distributed lock service is not received after 100 milliseconds from the sending of the locking request, sending the locking request to the distributed lock service again, if the locking success prompt returned by the distributed lock service is still not received after 100 milliseconds from the sending of the locking request, sending the locking request to the distributed lock service again, and if the time length for accumulating the locking success prompt reaches 10 seconds, determining that the locking fails and generating a locking failure prompt if the locking success prompt returned by the distributed lock service is still not received.
In the embodiment of the present invention, the inventory deduction method of the present invention may further include:
for any to-be-locked commodity ID, if the distributed lock service does not receive an unlocking request within a time period of a third preset duration from the time of locking the to-be-locked commodity ID, the distributed lock service automatically unlocks the to-be-locked commodity ID.
Thus, it is prevented that certain orders occupy the distributed lock service for a long time, and other orders are influenced to call the distributed lock service.
In the embodiment of the invention, inventory deduction is performed on all commodities, which specifically may include:
(1) And sending an inventory inquiry request to the commodity inventory database, wherein the inventory inquiry request contains commodity IDs of all commodities.
(2) And receiving commodity inventory data returned by the commodity inventory database, wherein the commodity inventory data comprises inventory numbers of all commodities.
(3) And carrying out inventory analysis according to the commodity inventory data and commodity purchase quantity of all commodities, wherein the commodity data also comprises the commodity purchase quantity.
Specifically, the step may specifically include taking each commodity as a target commodity one by one, and executing the following steps:
a. and determining the inventory quantity of the target commodity according to the commodity inventory data.
b. And determining the commodity purchase quantity of the target commodity according to the commodity purchase quantity of all commodities.
c. Judging whether the stock quantity of the target commodity is smaller than the commodity purchase quantity of the target commodity; if the inventory quantity of the target commodity is smaller than the commodity purchase quantity of the target commodity, determining that the inventory of the target commodity is insufficient; and if the stock quantity of the target commodity is not less than the commodity purchase quantity of the target commodity, determining that the stock of the target commodity is sufficient.
(4) And if the analysis result shows that the commodity with insufficient inventory exists, generating a commodity inventory shortage prompt.
(5) If the analysis result shows that the inventory-deficient commodities are not available, calculating the remaining quantity of all the commodities after inventory deduction according to commodity inventory data and commodity purchase quantity of all the commodities.
(6) And generating an inventory update request according to the residual quantity of all the commodities subjected to inventory deduction.
(7) And sending the inventory update request to the commodity inventory database so that the commodity inventory database updates the inventory quantity of all commodities.
According to the technical scheme, the inventory inquiry request is sent to the commodity inventory database to acquire the inventory quantity of all commodities in the order at one time, then the inventory analysis is carried out locally, and when the analysis result shows that the commodities with insufficient inventory do not exist, the inventory quantity of all the commodities is updated at one time by sending the inventory update request to the commodity inventory database. That is, in the invention, when inventory deduction is carried out on all commodities in an order, only two interactions are needed with the commodity inventory database, so that the invention can reduce the times of interactions with the commodity inventory database, reduce the access pressure of the commodity inventory database, reduce the influence of network delay on the inventory deduction time length, and further improve the processing efficiency of the order.
In the embodiment of the present invention, the inventory deduction method of the present invention may further include:
and when the inventory shortage of any commodity is determined for the first time, ending the inventory analysis.
In order to more clearly describe the above technical solution, the above stock deduction method is described in the following.
Fig. 2 is a flow chart of another inventory deduction method according to an embodiment of the present invention. As shown in fig. 2, the present stock deduction method includes:
step 201: order request data sent by a user side terminal is received, the order request data comprises commodity data of a plurality of commodities, and the commodity data comprises commodity IDs and commodity purchase quantities.
Step 202: the commodity IDs of all the commodities in the order request data are extracted.
Step 203: the commodity IDs of all commodities are deduplicated.
Step 204: and sending a locking request containing the duplicate product ID to the distributed locking service so that the distributed locking service locks the duplicate product ID.
Step 205: whether a successful locking prompt returned by the distributed lock service is received is determined, if the successful locking prompt returned by the distributed lock service is not received, step 206 is executed, and if the successful locking prompt returned by the distributed lock service is received, step 207 is executed.
Step 206: after waiting for the first preset time period from the latest time of sending the locking request, if the time period for waiting for the locking success prompt does not reach the second preset time period, executing step 204, if the time period for waiting for the locking success prompt reaches the second preset time period, determining that the locking fails, and generating a locking failure prompt.
Step 207: and sending an inventory inquiry request to the commodity inventory database, wherein the inventory inquiry request contains commodity IDs of all commodities.
Step 208: and receiving commodity inventory data returned by the commodity inventory database, wherein the commodity inventory data comprises inventory numbers of all commodities.
Step 209: based on the commodity inventory data and the commodity purchase quantity of all commodities, inventory analysis is performed, if the analysis result indicates that there is a commodity with insufficient inventory, step 210 is performed, and if the analysis result indicates that there is no commodity with insufficient inventory, step 211 is performed.
Step 210: and generating a commodity inventory shortage prompt.
Step 211: and calculating the residual quantity of all the commodities after inventory deduction according to the commodity inventory data and the commodity purchase quantity of all the commodities.
Step 212: and generating an inventory update request according to the residual quantity of all the commodities subjected to inventory deduction.
Step 213: and sending the inventory update request to the commodity inventory database so that the commodity inventory database updates the inventory quantity of all commodities.
Step 214: and sending an unlocking request containing the duplicate removed commodity ID to the distributed lock service so as to enable the distributed lock service to unlock the locked duplicate removed commodity ID.
In summary, the inventory deduction method of the invention can reduce the interaction times with the distributed lock service and the commodity inventory database by carrying out batch locking and unlocking and batch inventory inquiry and deduction on the ordered commodities, thereby reducing the access pressure of the distributed lock service and the commodity inventory database, reducing the influence of network delay on the processing efficiency of the inventory deduction method, reducing the network communication cost and improving the order processing efficiency.
Based on a general inventive concept, the invention also provides an inventory deduction device. Fig. 3 is a schematic structural diagram of an inventory deduction device according to an embodiment of the present invention. As shown in fig. 3, the present stock deduction device includes:
the order receiving data module 31 is configured to receive order request data sent by a user terminal, where the order request data includes commodity data of a plurality of commodities, and the commodity data includes commodity IDs.
The locking request generation module 32 is configured to generate a locking request according to the order request data, where the locking request includes all the IDs of the goods to be locked.
The locking module 33 is configured to send a locking request to the distributed locking service, so that the distributed locking service locks all the to-be-locked product IDs, and for any to-be-locked product ID, if the distributed locking service does not receive an unlocking request within a period of a third preset duration from when the to-be-locked product ID is locked, the distributed locking service automatically unlocks the to-be-locked product ID.
The inventory deduction module 34 is configured to, when receiving a locking success prompt returned by the distributed lock service, perform inventory deduction on all the commodities.
And the unlocking module 35 is configured to send an unlocking request to the distributed lock service after the inventory deduction is successfully performed on all the commodities, so that the distributed lock service unlocks all the to-be-unlocked commodity IDs, and the unlocking request contains all the to-be-unlocked commodity IDs.
Optionally, the generation locking request module 32 may be specifically configured to:
(1) And analyzing the order request data to obtain the commodity IDs of all the commodities.
(2) The commodity IDs of all commodities are deduplicated.
(3) And generating a locking request according to the duplicate product ID after duplicate removal, wherein the locking request contains the duplicate product ID after duplicate removal.
Optionally, the inventory deduction device of the present invention may further include:
and the repeated locking module is used for executing the step of sending the locking request to the distributed lock service if the locking success prompt returned by the distributed lock service is not received within the time period of the first preset time period from the sending of the locking request until the time period of accumulating waiting for the locking success prompt reaches the second preset time period, and determining that the locking fails if the locking success prompt returned by the distributed lock service is still not received.
Alternatively, the distributed lock service is a Redis Cluster, and the distributed lock service uses Lua script.
Optionally, the inventory deduction module 34 may specifically include:
the inventory inquiry request sending sub-module is used for sending an inventory inquiry request to the commodity inventory database, wherein the inventory inquiry request contains commodity IDs of all commodities.
The commodity inventory receiving data sub-module is used for receiving commodity inventory data returned by the commodity inventory database, wherein the commodity inventory data comprises inventory numbers of all commodities.
And the inventory analysis sub-module is used for carrying out inventory analysis according to commodity inventory data and commodity purchase quantity of all commodities, wherein the commodity data also comprises the commodity purchase quantity.
And the inventory shortage prompting sub-module is used for generating a commodity inventory shortage prompt if the analysis result shows that the commodity with the inventory shortage exists.
And the calculation sub-module is used for calculating the residual quantity of all commodities after inventory deduction according to commodity inventory data and commodity purchase quantity of all commodities if the analysis result shows that the commodities with insufficient inventory do not exist.
And the inventory update generation request sub-module is used for generating an inventory update request according to the residual quantity of all the commodities subjected to inventory deduction.
And the inventory updating sub-module is used for sending an inventory updating request to the commodity inventory database so that the commodity inventory database updates the inventory quantity of all commodities.
Optionally, the inventory analysis sub-module may be specifically configured to:
(1) The respective commodities are taken as target commodities one by one, and the following steps are performed.
(2) And determining the inventory quantity of the target commodity according to the commodity inventory data.
(3) And determining the commodity purchase quantity of the target commodity according to the commodity purchase quantity of all commodities.
(4) And judging whether the stock quantity of the target commodity is smaller than the commodity purchase quantity of the target commodity.
(5) If the inventory quantity of the target commodity is smaller than the commodity purchase quantity of the target commodity, determining that the inventory of the target commodity is insufficient.
(6) And if the stock quantity of the target commodity is not less than the commodity purchase quantity of the target commodity, determining that the stock of the target commodity is sufficient.
Optionally, the inventory analysis sub-module may be further specifically configured to:
and when the inventory shortage of any commodity is determined for the first time, ending the inventory analysis.
For the foregoing method embodiments, for simplicity of explanation, the methodologies are shown as a series of acts, but one of ordinary skill in the art will appreciate that the present invention is not limited by the order of acts, as some steps may, in accordance with the present invention, occur in other orders or concurrently. Further, those skilled in the art will also appreciate that the embodiments described in the specification are all preferred embodiments, and that the acts and modules referred to are not necessarily required for the present invention.
It should be noted that, in the present specification, each embodiment is described in a progressive manner, and each embodiment is mainly described as different from other embodiments, and identical and similar parts between the embodiments are all enough to be referred to each other. For the apparatus class embodiments, the description is relatively simple as it is substantially similar to the method embodiments, and reference is made to the description of the method embodiments for relevant points.
The steps in the method of each embodiment of the invention can be sequentially adjusted, combined and deleted according to actual needs, and the technical features described in each embodiment can be replaced or combined.
The modules and the submodules in the device and the terminal of the embodiments of the invention can be combined, divided and deleted according to actual needs.
In the embodiments provided in the present invention, it should be understood that the disclosed terminal, apparatus and method may be implemented in other manners. For example, the above-described terminal embodiments are merely illustrative, and for example, the division of modules or sub-modules is merely a logical function division, and there may be other manners of division in actual implementation, for example, multiple sub-modules or modules may be combined or integrated into another module, or some features may be omitted, or not performed. Alternatively, the coupling or direct coupling or communication connection shown or discussed with each other may be an indirect coupling or communication connection via some interfaces, devices or modules, which may be in electrical, mechanical, or other forms.
The modules or sub-modules illustrated as separate components may or may not be physically separate, and components that are modules or sub-modules may or may not be physical modules or sub-modules, i.e., may be located in one place, or may be distributed over multiple network modules or sub-modules. Some or all of the modules or sub-modules may be selected according to actual needs to achieve the purpose of the embodiment.
In addition, each functional module or sub-module in the embodiments of the present invention may be integrated in one processing module, or each module or sub-module may exist alone physically, or two or more modules or sub-modules may be integrated in one module. The integrated modules or sub-modules may be implemented in hardware or in software functional modules or sub-modules.
Those of skill would further appreciate that the various illustrative elements and algorithm steps described in connection with the embodiments disclosed herein may be implemented as electronic hardware, computer software, or combinations of both, and that the various illustrative elements and steps are described above generally in terms of functionality in order to clearly illustrate the interchangeability of hardware and software. Whether such functionality is implemented as hardware or software depends upon the particular application and design constraints imposed on the solution. Skilled artisans may implement the described functionality in varying ways for each particular application, but such implementation decisions should not be interpreted as causing a departure from the scope of the present invention.
The steps of a method or algorithm described in connection with the embodiments disclosed herein may be embodied directly in hardware, in a software unit executed by a processor, or in a combination of the two. The software elements may be disposed in Random Access Memory (RAM), memory, read Only Memory (ROM), electrically programmable ROM, electrically erasable programmable ROM, registers, hard disk, a removable disk, a CD-ROM, or any other form of storage medium known in the art.
Finally, it is further noted that relational terms such as first and second, and the like are used solely to distinguish one entity or action from another entity or action without necessarily requiring or implying any actual such relationship or order between such entities or actions. Moreover, the terms "comprises," "comprising," or any other variation thereof, are intended to cover a non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements does not include only those elements but may include other elements not expressly listed or inherent to such process, method, article, or apparatus. Without further limitation, an element defined by the phrase "comprising one … …" does not exclude the presence of other like elements in a process, method, article, or apparatus that comprises the element.
The previous description of the disclosed embodiments is provided to enable any person skilled in the art to make or use the present invention. Various modifications to these embodiments will be readily apparent to those skilled in the art, and the generic principles defined herein may be applied to other embodiments without departing from the spirit or scope of the invention. Thus, the present invention is not intended to be limited to the embodiments shown herein but is to be accorded the widest scope consistent with the principles and novel features disclosed herein.

Claims (10)

1. A stock deduction method, comprising:
receiving order request data sent by a user side terminal, wherein the order request data comprises commodity data of a plurality of commodities, and the commodity data comprises commodity IDs;
generating a locking request according to the order request data, wherein the locking request contains all the IDs of the commodities to be locked;
sending the locking request to a distributed lock service so that the distributed lock service locks all the to-be-locked commodity IDs;
when a locking success prompt returned by the distributed lock service is received, carrying out inventory deduction on all commodities;
and after the inventory deduction is successfully carried out on all the commodities, an unlocking request is sent to the distributed lock service so that the distributed lock service can unlock all the commodity IDs to be unlocked, and the unlocking request contains all the commodity IDs to be unlocked.
2. The inventory deduction method according to claim 1, wherein generating a locking request according to the order request data specifically comprises:
analyzing the order request data to obtain commodity IDs of all the commodities;
duplicate removal of commodity IDs of all the commodities;
and generating the locking request according to the duplicate commodity ID after duplicate removal, wherein the locking request comprises the duplicate commodity ID after duplicate removal.
3. The inventory deduction method according to claim 1, further comprising, after sending the locking request to a distributed lock service:
if the locking success prompt returned by the distributed lock service is not received within the time period of the first preset time period from the sending of the locking request, the step of sending the locking request to the distributed lock service is executed until the time period for waiting for the locking success prompt reaches the second preset time period, and if the locking success prompt returned by the distributed lock service is still not received, the locking failure is determined.
4. The inventory deduction method according to claim 1, further comprising:
for any to-be-locked commodity ID, if the distributed lock service does not receive the unlocking request within a time period of a third preset duration from the time of completing locking of the to-be-locked commodity ID, the distributed lock service automatically unlocks the to-be-locked commodity ID.
5. The inventory deduction method according to claim 1, wherein the distributed lock service is a dis Cluster and the distributed lock service uses Lua script.
6. The stock deduction method according to claim 1, wherein the stock deduction is performed on all the commodities, specifically comprising:
sending an inventory inquiry request to a commodity inventory database, wherein the inventory inquiry request comprises commodity IDs of all commodities;
receiving commodity inventory data returned by the commodity inventory database, wherein the commodity inventory data comprises inventory numbers of all commodities;
performing inventory analysis according to the commodity inventory data and commodity purchase quantity of all commodities, wherein the commodity data further comprises commodity purchase quantity;
if the analysis result shows that the inventory-deficient commodity exists, generating a commodity inventory-deficient prompt;
if the analysis result shows that the inventory-deficient commodities do not exist, calculating the remaining quantity of all the commodities after inventory deduction according to the commodity inventory data and the commodity purchase quantity of all the commodities;
generating an inventory update request according to the residual quantity after inventory deduction of all the commodities;
and sending the inventory updating request to the commodity inventory database so that the commodity inventory database updates the inventory quantity of all the commodities.
7. The inventory deduction method according to claim 6, wherein the inventory analysis is performed according to the commodity inventory data and the commodity purchase quantity of all the commodities, and specifically comprises:
taking each commodity as a target commodity one by one, and executing the following steps:
determining the stock quantity of the target commodity according to the commodity stock data;
determining the commodity purchase quantity of the target commodity according to the commodity purchase quantity of all the commodities;
judging whether the stock quantity of the target commodity is smaller than the commodity purchase quantity of the target commodity;
if the stock quantity of the target commodity is smaller than the commodity purchase quantity of the target commodity, determining that the stock of the target commodity is insufficient;
and if the stock quantity of the target commodity is not less than the commodity purchase quantity of the target commodity, determining that the stock of the target commodity is sufficient.
8. The inventory deduction method according to claim 7, further comprising:
and when the inventory shortage of any commodity is determined for the first time, ending the inventory analysis.
9. An inventory deduction device, comprising:
the order receiving data module is used for receiving order request data sent by the user side terminal, wherein the order request data comprises commodity data of a plurality of commodities, and the commodity data comprises commodity IDs;
the locking request generation module is used for generating a locking request according to the order request data, wherein the locking request comprises all the to-be-locked commodity IDs;
the locking module is used for sending the locking request to a distributed locking service so that the distributed locking service locks all the to-be-locked commodity IDs;
the inventory deduction module is used for performing inventory deduction on all the commodities when receiving a locking success prompt returned by the distributed lock service;
and the unlocking module is used for sending an unlocking request to the distributed lock service after the inventory deduction is successfully carried out on all the commodities so as to enable the distributed lock service to unlock all the commodity IDs to be unlocked, wherein the unlocking request comprises all the commodity IDs to be unlocked.
10. The stock deduction device according to claim 9, wherein the stock deduction module is specifically configured to:
sending an inventory inquiry request to a commodity inventory database, wherein the inventory inquiry request comprises commodity IDs of all commodities;
receiving commodity inventory data returned by the commodity inventory database, wherein the commodity inventory data comprises inventory numbers of all commodities;
performing inventory analysis according to the commodity inventory data and commodity purchase quantity of all commodities, wherein the commodity data further comprises commodity purchase quantity;
if the analysis result shows that the inventory-deficient commodity exists, generating a commodity inventory-deficient prompt;
if the analysis result shows that the inventory-deficient commodities do not exist, calculating the remaining quantity of all the commodities after inventory deduction according to the commodity inventory data and the commodity purchase quantity of all the commodities;
generating an inventory update request according to the residual quantity after inventory deduction of all the commodities;
and sending the inventory updating request to the commodity inventory database so that the commodity inventory database updates the inventory quantity of all the commodities.
CN202311370761.1A 2023-10-20 2023-10-20 Inventory deduction method and device Pending CN117611269A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202311370761.1A CN117611269A (en) 2023-10-20 2023-10-20 Inventory deduction method and device

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202311370761.1A CN117611269A (en) 2023-10-20 2023-10-20 Inventory deduction method and device

Publications (1)

Publication Number Publication Date
CN117611269A true CN117611269A (en) 2024-02-27

Family

ID=89956846

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202311370761.1A Pending CN117611269A (en) 2023-10-20 2023-10-20 Inventory deduction method and device

Country Status (1)

Country Link
CN (1) CN117611269A (en)

Similar Documents

Publication Publication Date Title
CN111752957B (en) Sale locking method and system based on caching
CN107341624B (en) Service data processing method and device
EP3306904B1 (en) System and method for automatic recharging of a virtual resource
CN112688799B (en) Redis cluster-based client number distribution method and distribution device
CN112817995B (en) Data processing method and device, electronic equipment and storage medium
CN110704486B (en) Data processing method, device, system, storage medium and server
CN103793843A (en) Account data processing method and device
CN106779974B (en) Article transaction method and system
CN111311360A (en) Resource return method and device, storage medium and electronic device
CN108667872A (en) Archiving method and device for dispatch server
CN117611269A (en) Inventory deduction method and device
CN111539703B (en) Payment exception handling method and system
CN111784910A (en) Control system and method of intelligent device
CN107038617B (en) Pre-creation method and device of payment order
CN107146075B (en) Request processing method and device
CN115131067A (en) Data processing method and device, electronic equipment and storage medium
CN110795445B (en) Concurrent task processing method and device, server equipment and medium
CN114358866A (en) Method and device for locking commodity inventory
CN111199396B (en) Self-help shopping method and system
CN111524011A (en) Parallel chain consensus confirming method, equipment and storage medium
CN112749176A (en) Synchronous processing method and device of inventory data, storage medium and server
CN110751237A (en) Product management method based on one-object-one-code
CN112054928B (en) Parallel chain node configuration method, equipment and storage medium
CN114283010B (en) Multi-main-chain crossing method based on multi-main-chain two-layer network state tree
CN117952508A (en) Inventory processing method, inventory processing device, electronic equipment, storage medium and product

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination