Skip to content

Commit

Permalink
fix 少卖
Browse files Browse the repository at this point in the history
  • Loading branch information
gongfukangEE committed Jun 8, 2019
1 parent 007ffb0 commit 42ecd6a
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 27 deletions.
45 changes: 25 additions & 20 deletions .idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ public class IndexController {
@RequestMapping(value = "createWrongOrder", method = RequestMethod.POST)
@ResponseBody
public String createWrongOrder(HttpServletRequest request, int sid) {
log.info("sid = [{}]", sid);
int res = 0;
try {
res = orderService.createWrongOrder(sid);
Expand All @@ -58,7 +57,6 @@ public String createWrongOrder(HttpServletRequest request, int sid) {
@RequestMapping(value = "createOptimisticOrder", method = RequestMethod.POST)
@ResponseBody
public String createOptimisticOrder(HttpServletRequest request, int sid) {
log.info("sid = [{}]", sid);
int res = 0;
try {
res = orderService.createOptimisticOrder(sid);
Expand All @@ -76,7 +74,6 @@ public String createOptimisticOrder(HttpServletRequest request, int sid) {
@RequestMapping(value = "createOptimisticLimitOrder", method = RequestMethod.POST)
@ResponseBody
public String createOptimisticLimitOrder(HttpServletRequest request, int sid) {
log.info("sid = [{}]", sid);
int res = 0;
try {
if (RedisLimit.limit()) {
Expand All @@ -96,7 +93,6 @@ public String createOptimisticLimitOrder(HttpServletRequest request, int sid) {
@RequestMapping(value = "createOrderWithLimitAndRedis", method = RequestMethod.POST)
@ResponseBody
public String createOrderWithLimitAndRedis(HttpServletRequest request, int sid) {
log.info("sid = [{}]", sid);
int res = 0;
try {
if (RedisLimit.limit()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ private Stock checkStockWithRedis(int sid) throws Exception {
Integer count = Integer.parseInt(data.get(0));
Integer sale = Integer.parseInt(data.get(1));
Integer version = Integer.parseInt(data.get(2));
if (count.equals(sale) || count <= 0) {
log.info("库存不足 Redis currentCount: {}" + sale);
if (count <= 0) {
log.info("库存不足");
throw new RuntimeException("库存不足 Redis currentCount: " + sale);
}
Stock stock = new Stock();
Expand Down Expand Up @@ -109,7 +109,7 @@ private void saleStockOptimsticWithRedis(Stock stock) throws Exception{
*/
private Stock checkStock(int sid) throws Exception{
Stock stock = stockService.getStockById(sid);
if (stock.getCount() <= 0 || stock.getSale().equals(stock.getCount())) {
if (stock.getCount() <= 0) {
throw new RuntimeException("库存不足");
}
return stock;
Expand Down

0 comments on commit 42ecd6a

Please sign in to comment.