记得上下班打卡 | git大法好,push需谨慎

Commit 5c5d7c58 authored by 胡佳晨's avatar 胡佳晨

脚本增加锁逻辑

parent 4e185e95
...@@ -1015,6 +1015,9 @@ public class KylinOrderTicketsServiceImpl extends ServiceImpl<KylinOrderTicketsM ...@@ -1015,6 +1015,9 @@ public class KylinOrderTicketsServiceImpl extends ServiceImpl<KylinOrderTicketsM
@Override @Override
public boolean checkOrderTime(String userId) { public boolean checkOrderTime(String userId) {
String lock = "order_lock:checkOrderTime:" + userId;
try {
if (redisLockUtil.tryLock(lock, 1, 3600)) {
List<OrderScriptDto> dtoData = orderTicketsMapper.orderScriptDto(userId); List<OrderScriptDto> dtoData = orderTicketsMapper.orderScriptDto(userId);
HashMap<String, Integer> map2 = new HashMap<>(); HashMap<String, Integer> map2 = new HashMap<>();
Integer count = 0; Integer count = 0;
...@@ -1023,14 +1026,9 @@ public class KylinOrderTicketsServiceImpl extends ServiceImpl<KylinOrderTicketsM ...@@ -1023,14 +1026,9 @@ public class KylinOrderTicketsServiceImpl extends ServiceImpl<KylinOrderTicketsM
for (OrderScriptDto item : dtoData) { for (OrderScriptDto item : dtoData) {
count += 1; count += 1;
LinkedList<String> sqls = new LinkedList<>(); LinkedList<String> sqls = new LinkedList<>();
String lock = "order_lock:" + item.getOrderCode();
// if (!redisLockUtil.tryLock(lock, 30, 240)) {
// continue;
// }
if (item.getStatus() == KylinTableStatusConst.ORDER_STATUS0) { if (item.getStatus() == KylinTableStatusConst.ORDER_STATUS0) {
LocalDateTime now = LocalDateTime.now(); LocalDateTime now = LocalDateTime.now();
try { try {
KylinOrderTicketVo vo = dataUtils.getOrderTicketVo(item.getOrderTicketsId()); KylinOrderTicketVo vo = dataUtils.getOrderTicketVo(item.getOrderTicketsId());
if (vo.getStatus() != 0) { if (vo.getStatus() != 0) {
continue; continue;
...@@ -1090,24 +1088,27 @@ public class KylinOrderTicketsServiceImpl extends ServiceImpl<KylinOrderTicketsM ...@@ -1090,24 +1088,27 @@ public class KylinOrderTicketsServiceImpl extends ServiceImpl<KylinOrderTicketsM
rabbitTemplate.convertAndSend(MQConst.EXCHANGES_LIQUIDNET_SQL_ORDER_CLOSE, MQConst.ROUTING_KEY_SQL_ORDER_CLOSE, SqlMapping.gets(sqls, sqlsDataA, sqlsDataB, sqlsDataC)); rabbitTemplate.convertAndSend(MQConst.EXCHANGES_LIQUIDNET_SQL_ORDER_CLOSE, MQConst.ROUTING_KEY_SQL_ORDER_CLOSE, SqlMapping.gets(sqls, sqlsDataA, sqlsDataB, sqlsDataC));
mqCount += 1; mqCount += 1;
} catch (Exception e) { } catch (Exception e) {
//redisLockUtil.unlock(lock);
log.debug("CHECK TIME SYNC = " + e.getMessage()); log.debug("CHECK TIME SYNC = " + e.getMessage());
e.printStackTrace(); e.printStackTrace();
return false; return false;
} }
} else {
//redisLockUtil.unlock(lock);
} }
} }
log.debug("COUNT 1 = " + count); log.debug("COUNT 1 = " + count);
log.debug("COUNT 2 = " + mqCount); log.debug("COUNT 2 = " + mqCount);
log.debug("COUNT 3 = " + Acount); log.debug("COUNT 3 = " + Acount);
for (Map.Entry<String, Integer> entry : map2.entrySet()) { for (Map.Entry<String, Integer> entry : map2.entrySet()) {
dataUtils.changeSurplusGeneral(entry.getKey(), entry.getValue()); dataUtils.changeSurplusGeneral(entry.getKey(), entry.getValue());
} }
} else {
log.debug("WARNING LOCKING" );
}
} catch (Exception e) {
redisLockUtil.unlock(lock);
return false;
} finally {
redisLockUtil.unlock(lock);
}
return true; return true;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment