可以秒杀成功,但是重复秒杀的时候。execution的Response是{"success":false,"data":{"seckillId":1000,"state":-2,"stateInfo":"系统异常","successKilled":null},"error":null}。
修改一下,SeckillController 类中的 加粗的位置即可
@ResponseBody
@RequestMapping(value = "/{seckillId}/{md5}/execution", method = RequestMethod.POST, produces = {"application/json;charset=UTF-8"})
public SeckillResult<SeckillExecution> execute(@PathVariable("seckillId") Long seckillId,
@PathVariable("md5") String md5,
@CookieValue(value = "killPhone", required = false) Long phone) {
if (phone == null){
return new SeckillResult<SeckillExecution>(false,"未注册登录的用户");
}
try {
SeckillExecution seckillExecution = seckillService.executeSeckill(seckillId, phone, md5);
return new SeckillResult<SeckillExecution>(true,seckillExecution);
}catch (RepeatKillException e){
SeckillExecution execution = new SeckillExecution(seckillId, SeckillStateEnum.REPEAT_KILL);
return new SeckillResult<SeckillExecution>(true,execution);
}catch (SeckillCloseException e){
SeckillExecution execution = new SeckillExecution(seckillId, SeckillStateEnum.END);
return new SeckillResult<SeckillExecution>(true,execution);
}catch (Exception e){
logger.error(e.getMessage(),e);
SeckillExecution execution = new SeckillExecution(seckillId, SeckillStateEnum.INNER_ERROR);
return new SeckillResult<SeckillExecution>(true,execution);
}
}