Another solution for scheduled product loading and unloading, no need for scheduled tasks and additional controls, pure logical processing, high efficiency and low consumption

Table of contents

Foreword:

Solution:

1. Define product status:

2. Conditions must be met:

3. Business logic processing method:

4. Code examples:


Foreword:

        During this period of time, I was starting a business and developing a system similar to an e-commerce platform. I encountered the problem of scheduled loading and unloading. I checked a lot of information on the Internet and found that all solutions were solved by scheduled tasks. I felt it was very poor. So after thinking and researching, I came up with this plan. Most of the current solutions are to actively change the status of the product. Whether it's a scheduled task polling products in the database, a redis cache validity period, or something else. Without exception, they are all proactive operations. This method is inefficient, consumes a lot of money, is inflexible, and the scheduled shelf time is not accurate. For a data volume like Taobao, there are N merchants, and the merchants will have at least dozens of products. If the product status is changed to on the shelf through scheduled task polling, efficiency cannot be guaranteed at all, and the performance consumption is extremely high. So I worked out another solution for scheduled loading and unloading, which is passive timing (that’s what I named it for now). If I guess correctly, Taobao should be the same way.

        If you have any questions or problems with this plan, please leave a message below and we will solve it together. In the future, I will contribute more technical development solutions for e-commerce for free. If you have any questions, please leave a message

Solution:

1. Define product status:

On-shelf (sale), scheduled on-shelf (fake-on-shelf), off-shelf (warehouse)

2. Conditions must be met:

1. Products that have been put on the shelf do not support the scheduled shelf setting.
2. After a certain product or batch of products is set to be scheduled to be put on the shelf, the product will be in the pseudo-shelf function. And the products cannot be put on the shelves immediately unless they are removed from the shelves first.
3. The removed products are not subject to scheduled task management, but they can be put on the shelves again manually or at a scheduled time.

3. Business logic processing method:

Each time a certain product or product list is queried (the product list query must be paginated, so the one-time amount will definitely not be particularly large)

Needless to say about search engines, it’s the same

If it is just a separate scheduled listing without removing it, you can first have the logic, and then slowly modify the status through scheduled tasks, or you can just use this logic directly. No need to worry about the status of the database

(1). The logic processing of the unavailable shelf time
        uses SQL scripts or codes to determine the current time and the shelf time.
        If the current time is less than the shelf time, the product status is directly returned to the pseudo-shelf state
  
. (2) The shelf time has been reached, but the shelf time has not yet arrived. Shelf time logic processing    
     uses SQL scripts or codes to determine the current time and shelf time.
     If the current time is greater than or equal to and less than the removal time, the product status is directly returned to the shelf status
                          
(3). The logic processing of the removal time has reached
     through SQL scripts or The code determines the current time and the removal time.
     If the current time is greater than or equal to the removal time, the product status is directly returned to the removal status.

4. Code examples:

Assumption: product status, 1-on-shelf, 0-off-shelf, 2-timed on-shelf and off-shelf

if (vo.getShelfStatus()==2){
	//当前时间大于等于自动上架时间,则为上架状态,否则是定时上架下架状态
	vo.setShelfStatus(new Date().compareTo(vo.getAutoShelfTime())>-1?1:vo.getShelfStatus());
	//当前时间大于等于自动下架时间,则为下架状态,否则是上架状态
	vo.setShelfStatus(new Date().compareTo(vo.getAutoSoldTime())>-1?0:vo.getShelfStatus());
}

Based on the above three logical judgments, they all revolve around the pseudo-on-shelf state, so as long as it is in the pseudo-on-shelf state, you can judge the time. If manual loading and unloading is required, just meet the three conditions mentioned above.

Whether it is business logic processing or data display, there is no problem with this solution. It is just a little more logic code for this kind of timing judgment.
     

Guess you like

Origin blog.csdn.net/Qensq/article/details/131446919