In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces "how to use Java to implement the second kill system". In daily operation, I believe many people have doubts about how to use Java to implement the second kill system. Xiaobian consulted all kinds of materials and sorted out simple and easy operation methods. I hope to help you answer the doubts about "how to use Java to implement the second kill system"! Next, please follow the small series to learn together!
Content:
As for the overall business process of the second kill system, I believe that smart friends will already know a rough idea after reading the second blog post! Because in the link to download the source code database provided, Debug has introduced the overall business process of the second kill system to all small partners.
A diagram is summarized, as shown in the following figure for the overall business process of the second kill system:
From the business flow diagram, it can be seen that when the backend interface receives the front-end instant kill request, its core processing logic is:
(1) First judge whether the current user has snapped up the commodity, if not, it means that the user has not snapped up the commodity, and can enter the next processing logic.
(2) Determine whether the remaining quantity of the commodity can be robbed, that is, whether the inventory is sufficient (that is, whether it is greater than 0). If yes, enter the next processing logic.
(3) Deduct inventory, update inventory corresponding to rush purchase record in database (generally minus one operation), judge whether database operation of updating inventory is successful, if yes, create order of user's second kill success, and asynchronously send SMS or email notification message to inform user.
(4) If any of the above operation logic steps does not meet the conditions, then the entire second kill process will be terminated directly, that is, the second kill will fail!
The following figure shows the core processing logic when the backend processes the "second kill request":
Synthesizing these two business processes, the database design of the "second kill system" is entered below, which mainly includes the following tables: item information table item_kill, second kill success record table item_kill_success and user information table user; of course, in actual large-scale websites, the database tables included are far more than this! The system temporarily condensed out of which the core of a few tables! The following figure shows the database design model of this "second kill system":
Then, reverse engineering of Mybatis is used to generate entity class Entity corresponding to these database tables, interface Mapper for operating Sql and configuration file Mapper.xml for writing dynamic Sql. As shown below:
Below, paste one of the entity classes and the corresponding Mapper interface and Mapper.xml code, others, you can click on the link: gitee.com/steadyjack/SpringBoot-SecondKill to download and view! First, the source code for the entity class ItemKill:
import com.fasterxml.jackson.annotation.JsonFormat;import lombok.Data;import java.util.Date;@Datapublic class ItemKill { private Integer id; private Integer itemId; private Integer total; @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "GMT+8") private Date startTime; @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "GMT+8") private Date endTime; private Byte isActive; @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "GMT+8") private Date createTime; private String itemName; //Use server time to control whether to snap up private Integer canKill;}
Then there is the source code for the ItemKillMapper interface:
import com.debug.kill.model.entity.ItemKill;import org.apache.ibatis.annotations.Param;import java.util.List;public interface ItemKillMapper { List selectAll(); ItemKill selectById(@Param("id") Integer id); int updateKillItem(@Param("killId") Integer killId); ItemKill selectByIdV2(@Param("id") Integer id); int updateKillItemV2(@Param("killId") Integer killId);}
Finally, the source code for the ItemKillMapper.xml configuration file:
SELECT a.*, b.name AS itemName, ( CASE WHEN (now() BETWEEN a.start_time AND a.end_time AND a.total > 0) THEN 1 ELSE 0 END ) AS canKill FROM item_kill AS a LEFT JOIN item AS b ON b.id = a.item_id WHERE a.is_active = 1 SELECT a.*, b.name AS itemName, ( CASE WHEN (now() BETWEEN a.start_time AND a.end_time AND a.total > 0) THEN 1 ELSE 0 END ) AS canKill FROM item_kill AS a LEFT JOIN item AS b ON b.id = a.item_id WHERE a.is_active = 1 AND a.id= #{id} UPDATE item_kill SET total = total - 1 WHERE id = #{killId} SELECT a.*, b.name AS itemName, (CASE WHEN (now() BETWEEN a.start_time AND a.end_time) THEN 1 ELSE 0 END) AS canKill FROM item_kill AS a LEFT JOIN item AS b ON b.id = a.item_id WHERE a.is_active = 1 AND a.id =#{id} AND a.total>0 UPDATE item_kill SET total = total - 1 WHERE id = #{killId} AND total>0
At this point, the study on "how to use Java to implement the second kill system" is over, hoping to solve everyone's doubts. Theory and practice can better match to help everyone learn, go and try it! If you want to continue learning more relevant knowledge, please continue to pay attention to the website, Xiaobian will continue to strive to bring more practical articles for everyone!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.