use of com.goodskill.entity.Seckill in project goodsKill by techa03.
the class BaseServiceConfigForTest method testSelect.
public Seckill testSelect() throws ExecutionException, InterruptedException {
Seckill seckill = (Seckill) redisTemplate.opsForValue().get(1000);
if (seckill == null) {
Seckill value;
if (signal.get()) {
putIntoJvm();
value = getFromJvm();
} else {
value = seckillMapper.selectById(1000);
updateRedis(value);
}
if (atomicBoolean.get()) {
System.out.println(Thread.currentThread().getName() + "已更新缓存:" + value.getNumber());
}
return value;
} else {
if (atomicBoolean.get()) {
System.out.println(Thread.currentThread().getName() + "获取到缓存:" + seckill.getNumber());
}
return seckill;
}
}
use of com.goodskill.entity.Seckill in project goodsKill by techa03.
the class BaseServiceConfigForTest method getFromJvm.
private Seckill getFromJvm() throws InterruptedException, ExecutionException {
BlockingQueue blockingQueue = taskQueue.get(Thread.currentThread());
Seckill seckill = null;
while (!blockingQueue.isEmpty()) {
Object object = blockingQueue.take();
reentrantLock.lock();
try {
if (object instanceof Callable) {
FutureTask futureTask = new FutureTask((Callable) object);
while (signal.get()) {
condition.await();
}
futureTask.run();
seckill = (Seckill) futureTask.get();
} else {
FutureTask futureTask = new FutureTask((Runnable) object, 1);
while (signal.get()) {
condition.await();
}
futureTask.run();
updateCount.decrementAndGet();
}
} finally {
reentrantLock.unlock();
}
}
return seckill;
}
use of com.goodskill.entity.Seckill in project goodsKill by techa03.
the class AlipayRunner method tradePrecreate.
public String tradePrecreate(long seckillId) {
Seckill seckill = redisService.getSeckill(seckillId);
Goods goods = goodsMapper.selectById(seckill.getGoodsId());
// 需保证商户系统端不能重复,建议通过数据库sequence生成,
String outTradeNo = "tradeprecreate" + System.currentTimeMillis() + (long) (Math.random() * 10000000L);
// 1. 设置参数(全局只需设置一次)
Factory.setOptions(getOptions());
try {
// 2. 发起API调用(以创建当面付收款二维码为例)
AlipayTradePrecreateResponse response = Factory.Payment.FaceToFace().preCreate(goods.getName(), outTradeNo, String.valueOf(seckill.getPrice()));
// 3. 处理响应或异常
if (ResponseChecker.success(response)) {
String finalQrcodeImagePath = String.format(qrcodeImagePath + "/qr-%s.png", response.outTradeNo);
ZxingUtils.getQRCodeImge(response.qrCode, 256, finalQrcodeImagePath);
log.info("支付宝当面扫调用成功!");
return finalQrcodeImagePath.split("/")[finalQrcodeImagePath.split("/").length - 1];
} else {
log.error("调用失败,原因:" + response.msg + "," + response.subMsg);
}
} catch (Exception e) {
log.error("调用遭遇异常,原因:" + e.getMessage());
}
return null;
}
use of com.goodskill.entity.Seckill in project goodsKill by techa03.
the class SeckillServiceImpl method reduceNumberInner.
@Transactional(rollbackFor = Exception.class)
@Override
public int reduceNumberInner(SuccessKilled successKilled) {
successKilledMapper.insert(successKilled);
Seckill wrapper = new Seckill();
wrapper.setSeckillId(successKilled.getSeckillId());
UpdateWrapper<Seckill> updateWrapper = new UpdateWrapper(wrapper);
updateWrapper.gt("end_time", successKilled.getCreateTime());
updateWrapper.lt("start_time", successKilled.getCreateTime());
updateWrapper.gt("number", 0);
updateWrapper.setSql("number = number - 1");
int update = baseMapper.update(null, updateWrapper);
if (update <= 0) {
throw new SeckillCloseException("seckill is closed");
} else {
taskExecutor.execute(() -> streamBridge.send(DEFAULT_BINDING_NAME_MONGO_SAVE, MessageBuilder.withPayload(SeckillMockSaveVo.builder().seckillId(successKilled.getSeckillId()).userPhone(successKilled.getUserPhone()).note(REDIS_MONGO_REACTIVE.getName()).build()).build()));
log.info("已发送");
return update;
}
}
use of com.goodskill.entity.Seckill in project goodsKill by techa03.
the class SeckillServiceImpl method getInfoById.
@Override
public SeckillInfoDTO getInfoById(Serializable seckillId) {
SeckillInfoDTO seckillInfoDTO = new SeckillInfoDTO();
Seckill seckill = seckillService.getById(seckillId);
Goods goods = goodsService.getById(seckill.getGoodsId());
BeanUtils.copyProperties(seckill, seckillInfoDTO);
seckillInfoDTO.setGoodsName(goods.getName());
return seckillInfoDTO;
}
Aggregations