当前位置:网站首页>[redis realize Secondary killing Business ①] Overview of Secondary killing Process | Basic Business Realization
[redis realize Secondary killing Business ①] Overview of Secondary killing Process | Basic Business Realization
2022-06-24 09:05:00 【Buster.】
Fruit shooting Business
Les gars,À partir d'aujourd'hui,On l'utilise ensembleRedisPour réaliser l'entreprise de Shooting,On va faire le plein ensemble!
Notre idée générale est de concevoir un petit projet fruitier.
D'abord, on aura un fruit,Le fruit a un nom、Nombre、L'heure de début et l'heure de fin du shopping.
Processus opérationnel
- La seconde mort commence ou se termine,Impossible de passer une commande si elle n'a pas encore commencé ou si elle est terminée
- Si les stocks sont suffisants,Pas assez pour passer une commande

Fruits solides

/** * Fruits * * @author issavior */
@Data
@AllArgsConstructor
@NoArgsConstructor
public class Fruits implements Serializable {
private static final long serialVersionUID = 1;
private Long id;
private String name;
private Integer count;
private Date startTime;
private Date endTime;
}
Nouveaux fruits
Controller
/** * @author issavior */
@RestController
@RequestMapping("/seckill")
public class SeckillController {
@Autowired
private SeckillService seckillService;
/** * Nouveaux fruits * @param fruits Fruits * @return ResponseEntity<Object> */
@PostMapping
public ResponseEntity<Object> insertFruits(@RequestBody Fruits fruits) {
return seckillService.insertFruits(fruits);
}
}
ServiceImpl
/** * @author issavior */
@Service
public class SeckillServiceImpl implements SeckillService {
@Autowired
private SeckillMapper seckillMapper;
@Autowired
private RedisIdWorker redisIdWorker;
/** * Nouveaux fruits * * @param fruits Nouvelles données sur les fruits * @return ResponseEntity<Object> */
@Override
public ResponseEntity<Object> insertFruits(Fruits fruits) {
// Unique au niveau mondialIDClasse d'outils, Pour plus de détails, voir l'article précédent de la série
long id = redisIdWorker.nextId("seckill:fruits");
fruits.setId(id);
int successFlag = seckillMapper.insertFruits(fruits);
if (successFlag == 0) {
return ResponseEntity.status(400).body("Impossible d'ajouter");
}
return ResponseEntity.ok("Ajouté avec succès");
}
}
Réalisation de base de l'entreprise de second kill
/** * Acheter des fruits * * @param id Clé principale pour acheter des fruits ID * @return ResponseEntity<Object> */
@PostMapping("/{id}")
public ResponseEntity<Object> seckillFruits(@PathVariable("id") Long id) {
return seckillService.seckillFruits(id);
}
/** * Acheter des fruits * * @param id Celui qui achète des fruits ID * @return ResponseEntity<Object> */
@Override
public ResponseEntity<Object> seckillFruits(Long id) {
Fruits fruits = seckillMapper.selectFruits(id);
if (fruits == null) {
return ResponseEntity.status(400).body(" Les fruits sont épuisés ,Revenez la prochaine fois.!");
}
LocalDateTime startTime = fruits.getStartTime();
LocalDateTime endTime = fruits.getEndTime();
Integer count = fruits.getCount();
if (startTime.isAfter(LocalDateTime.now())) {
return ResponseEntity.status(400).body("L'événement n'a pas encore commencé, Allez voir la page d'accueil de boolster !!");
}
if (endTime.isBefore(LocalDateTime.now())) {
return ResponseEntity.status(400).body("L'événement est terminé, Allez voir la page d'accueil de boolster !!");
}
if (count < 1) {
return ResponseEntity.status(400).body("Il n'y a plus de stock, Allez voir la page d'accueil de boolster !!");
}
int updateFruits = seckillMapper.updateFruits(id);
if (updateFruits == 0) {
return ResponseEntity.status(400).body(" Les fruits sont épuisés ,Revenez la prochaine fois.!");
}
return ResponseEntity.ok(" Succès de l'achat de fruits , Allez voir la page d'accueil de boolster !");
}
边栏推荐
- 双指针模拟
- IDEA另起一行快捷键
- Digital cloud released the 2022 white paper on digital operation of global consumers in the beauty industry: global growth solves marketing problems
- Telnet port login method with user name for liunx server
- Analyze the meaning of Internet advertising terms CPM, CPC, CPA, CPS, CPL and CPR
- 关于 GIN 的路由树
- Floating error waiting for changelog lock
- One article explains in detail | those things about growth
- 【NOI模拟赛】给国与时光鸡(构造)
- What is SRE? A detailed explanation of SRE operation and maintenance system
猜你喜欢

用VNC Viewer的方式远程连接无需显示屏的树莓派

Data middle office: middle office architecture and overview

Linux (centos7.9) installation and deployment of MySQL Cluster 7.6

Prompt code when MySQL inserts Chinese data due to character set problems: 1366

every()、map()、forEarch()方法。数组里面有对象的情况

Huawei Router: GRE Technology

听说你还在花钱从网上买 PPT 模板?

【LeetCode】541. Reverse string II

Target detection series fast r-cnn

【LeetCode】387. First unique character in string
随机推荐
普通人没有学历,自学编程可以月入过万吗?
Prompt code when MySQL inserts Chinese data due to character set problems: 1366
数云发布2022美妆行业全域消费者数字化经营白皮书:全域增长破解营销难题
Linux (centos7.9) installation and deployment of MySQL Cluster 7.6
"Unusual proxy initial value setting is not supported", causes and Solutions
[MySQL from introduction to mastery] [advanced part] (I) character set modification and underlying principle
linux(centos7.9)安装部署mysql-cluster 7.6
eBanb B1手环刷固件异常中断处理
MySQL - SQL statement
【量化投资】离散傅里叶变换求数组周期
110. balanced binary tree recursive method
Qingcloud based R & D cloud solution for geographic information enterprises
Implementation process of tcpdump packet capturing
KaFormer个人笔记整理
YOLOX backbone——CSPDarknet的实现
解决:模型训练时loss出现nan
Pytorch读入据集(典型数据集及自定义数据集两种模式)
华为路由器:GRE技术
基于QingCloud的地理信息企业研发云解决方案
【Pytorch基础教程31】YoutubeDNN模型解析