|
@@ -8,6 +8,8 @@ import com.fdkankan.common.constant.RecStatus;
|
|
import com.fdkankan.common.constant.RedisKey;
|
|
import com.fdkankan.common.constant.RedisKey;
|
|
import com.fdkankan.common.constant.TbStatus;
|
|
import com.fdkankan.common.constant.TbStatus;
|
|
import com.fdkankan.common.exception.BusinessException;
|
|
import com.fdkankan.common.exception.BusinessException;
|
|
|
|
+import com.fdkankan.redis.util.RedisLockUtil;
|
|
|
|
+import com.fdkankan.redis.util.RedisUtil;
|
|
import com.fdkankan.scene.entity.Scene3dNum;
|
|
import com.fdkankan.scene.entity.Scene3dNum;
|
|
import com.fdkankan.scene.mapper.IScene3dNumMapper;
|
|
import com.fdkankan.scene.mapper.IScene3dNumMapper;
|
|
import com.fdkankan.scene.service.IScene3dNumService;
|
|
import com.fdkankan.scene.service.IScene3dNumService;
|
|
@@ -34,7 +36,9 @@ import java.util.Objects;
|
|
public class Scene3dNumServiceImpl extends ServiceImpl<IScene3dNumMapper, Scene3dNum> implements IScene3dNumService {
|
|
public class Scene3dNumServiceImpl extends ServiceImpl<IScene3dNumMapper, Scene3dNum> implements IScene3dNumService {
|
|
|
|
|
|
@Autowired
|
|
@Autowired
|
|
- RedisTemplate redisTemplate;
|
|
|
|
|
|
+ RedisUtil redisUtil;
|
|
|
|
+ @Autowired
|
|
|
|
+ RedisLockUtil redisLockUtil;
|
|
|
|
|
|
@Override
|
|
@Override
|
|
public List<String> findSceneNum() {
|
|
public List<String> findSceneNum() {
|
|
@@ -61,23 +65,23 @@ public class Scene3dNumServiceImpl extends ServiceImpl<IScene3dNumMapper, Scene3
|
|
@Override
|
|
@Override
|
|
public String generateSceneNum(){
|
|
public String generateSceneNum(){
|
|
// 从缓存中获取
|
|
// 从缓存中获取
|
|
- String sceneNum = (String)redisTemplate.opsForList().leftPop(RedisKey.FDKANKAN_SCENE_NUMS);
|
|
|
|
|
|
+ String sceneNum = (String)redisUtil.lLeftPop(RedisKey.FDKANKAN_SCENE_NUMS);
|
|
if(Objects.nonNull(sceneNum)){
|
|
if(Objects.nonNull(sceneNum)){
|
|
return sceneNum;
|
|
return sceneNum;
|
|
}
|
|
}
|
|
// 分布式加锁
|
|
// 分布式加锁
|
|
- Long loading = redisTemplate.opsForValue().increment(RedisKey.LOCK_FDKANKAN_SCENE_NUMS);
|
|
|
|
|
|
+ Long loading = redisUtil.incr(RedisKey.LOCK_FDKANKAN_SCENE_NUMS, 1);
|
|
if (loading.compareTo(1L) == 0) {
|
|
if (loading.compareTo(1L) == 0) {
|
|
try {
|
|
try {
|
|
log.info("开始从数据库加载场景码");
|
|
log.info("开始从数据库加载场景码");
|
|
List<String> nums = this.findSceneNum();
|
|
List<String> nums = this.findSceneNum();
|
|
this.updateUsedStatus(nums);
|
|
this.updateUsedStatus(nums);
|
|
- redisTemplate.opsForList().rightPushAll(RedisKey.FDKANKAN_SCENE_NUMS, nums.toArray(new String[]{}));
|
|
|
|
|
|
+ redisUtil.lRightPushAll(RedisKey.FDKANKAN_SCENE_NUMS, nums);
|
|
log.info("场景码加载完成");
|
|
log.info("场景码加载完成");
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
e.printStackTrace();
|
|
e.printStackTrace();
|
|
} finally {
|
|
} finally {
|
|
- redisTemplate.opsForValue().decrement(RedisKey.LOCK_FDKANKAN_SCENE_NUMS);
|
|
|
|
|
|
+ redisUtil.decr(RedisKey.LOCK_FDKANKAN_SCENE_NUMS, 1);
|
|
}
|
|
}
|
|
}else{
|
|
}else{
|
|
// 等待1秒加载缓存
|
|
// 等待1秒加载缓存
|
|
@@ -87,7 +91,7 @@ public class Scene3dNumServiceImpl extends ServiceImpl<IScene3dNumMapper, Scene3
|
|
e.printStackTrace();
|
|
e.printStackTrace();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- sceneNum = (String)redisTemplate.opsForList().leftPop(RedisKey.FDKANKAN_SCENE_NUMS);
|
|
|
|
|
|
+ sceneNum = (String)redisUtil.lLeftPop(RedisKey.FDKANKAN_SCENE_NUMS);
|
|
if(StrUtil.isEmpty(sceneNum)){
|
|
if(StrUtil.isEmpty(sceneNum)){
|
|
log.error("场景码加载失败");
|
|
log.error("场景码加载失败");
|
|
throw new BusinessException(ErrorCode.FAILURE_CODE_5053);
|
|
throw new BusinessException(ErrorCode.FAILURE_CODE_5053);
|