|
@@ -0,0 +1,46 @@
|
|
|
+package com.iden.common.service.impl;
|
|
|
+
|
|
|
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import com.iden.common.cache.RedisKeyConstant;
|
|
|
+import com.iden.common.cache.RedisUtil;
|
|
|
+import com.iden.common.entity.IdenAutoincKey;
|
|
|
+import com.iden.common.mapper.IdenAutoincrKeyMapper;
|
|
|
+import com.iden.common.service.IdenAutoincrKeyService;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
+import javax.annotation.Resource;
|
|
|
+import java.util.UUID;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 市表(IdenCity)表æå¡å®ç°ç±»
|
|
|
+ *
|
|
|
+ * @author makejava
|
|
|
+ * @since 2021-12-30 19:06:40
|
|
|
+ */
|
|
|
+@Service
|
|
|
+public class IdenAutoincrKeyServiceImpl extends ServiceImpl<IdenAutoincrKeyMapper, IdenAutoincKey> implements IdenAutoincrKeyService {
|
|
|
+ @Resource
|
|
|
+ private RedisUtil redisUtil;
|
|
|
+ public Long updateMaxValue(String key){
|
|
|
+ String localKey = RedisKeyConstant.UID_KEY;
|
|
|
+ if("vuid".equals(key)){
|
|
|
+ localKey = RedisKeyConstant.VUID_KEY;
|
|
|
+ }
|
|
|
+ String requestId = UUID.randomUUID().toString();
|
|
|
+ boolean result = redisUtil.tryLock(localKey,requestId, 3);
|
|
|
+ Long maxValue = null;
|
|
|
+ try {
|
|
|
+ if (result) {
|
|
|
+ maxValue = this.baseMapper.updateMaxValue(key);
|
|
|
+ } else {
|
|
|
+ Thread.sleep(1000);
|
|
|
+ return updateMaxValue(key);
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.getMessage();
|
|
|
+ } finally {
|
|
|
+ redisUtil.releaseLock(localKey,requestId);
|
|
|
+ }
|
|
|
+ return maxValue;
|
|
|
+ }
|
|
|
+}
|