use of com.goodskill.common.exception.SeckillException in project goodsKill by techa03.
the class SeckillServiceImpl method executeSeckill.
@Transactional(rollbackFor = Exception.class)
@Override
public SeckillExecutionDTO executeSeckill(long seckillId, String userPhone, String md5) {
if (md5 == null || !md5.equals(MD5Util.getMD5(seckillId))) {
throw new SeckillException("seckill data rewrite");
}
Date nowTime = DateUtil.getNowTime();
try {
int updateCount = baseMapper.reduceNumber(seckillId, nowTime);
if (updateCount <= 0) {
throw new SeckillCloseException("seckill is closed");
} else {
SuccessKilled successKilled = new SuccessKilled();
successKilled.setSeckillId(seckillId);
successKilled.setUserPhone(userPhone);
int insertCount = successKilledMapper.insert(successKilled);
String qrfilepath = alipayRunner.tradePrecreate(seckillId);
if (insertCount <= 0) {
throw new RepeatKillException("seckill repeated");
} else {
SuccessKilled key = new SuccessKilled();
key.setSeckillId(seckillId);
key.setUserPhone(userPhone);
return new SeckillExecutionDTO(seckillId, SeckillStatEnum.SUCCESS.getStateInfo(), successKilledMapper.selectOne(new QueryWrapper<>(key)), qrfilepath);
}
}
} catch (SeckillCloseException | RepeatKillException e1) {
log.info(e1.getMessage(), e1);
throw e1;
} catch (Exception e) {
log.error(e.getMessage(), e);
throw new SeckillException("seckill inner error:" + e.getMessage());
}
}
Aggregations