lyhzzz 2 weeks ago
parent
commit
5997b0453c

+ 26 - 0
src/main/java/com/fdkankan/ucenter/config/ThreadPoolConfig.java

@@ -0,0 +1,26 @@
+package com.fdkankan.ucenter.config;
+
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.scheduling.annotation.EnableAsync;
+import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
+
+import java.util.concurrent.Executor;
+
+@Configuration
+@EnableAsync
+public class ThreadPoolConfig {
+
+    @Bean("taskExecutor")
+    public Executor taskExecutor() {
+        ThreadPoolTaskExecutor taskExecutor = new ThreadPoolTaskExecutor();
+        taskExecutor.setCorePoolSize(10);
+        taskExecutor.setMaxPoolSize(50);
+        taskExecutor.setQueueCapacity(200);
+        taskExecutor.setKeepAliveSeconds(60);
+        taskExecutor.setThreadNamePrefix("Thread-");
+        taskExecutor.setAwaitTerminationSeconds(60);
+        return taskExecutor;
+    }
+}
+

+ 9 - 2
src/main/java/com/fdkankan/ucenter/service/impl/SceneProServiceImpl.java

@@ -48,6 +48,7 @@ import org.joda.time.DateTime;
 import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
+import org.springframework.scheduling.annotation.Async;
 import org.springframework.stereotype.Service;
 import org.springframework.util.ObjectUtils;
 
@@ -214,9 +215,11 @@ public class SceneProServiceImpl extends ServiceImpl<ISceneProMapper, ScenePro>
         this.lockOrUnLockBySpace(cameraDetail,cameraId);
     }
 
+    @Autowired
+    private ExecutorService customThreadPool;
     @Override
     public void lockOrUnLockBySpace(CameraDetail cameraDetail, Long cameraId) {
-        ThreadUtil.execute(() -> {
+        customThreadPool.execute(() -> {
             log.info("异步任务执行,当前线程:" + Thread.currentThread().getName());
             List<SimpleSceneVo> voList = this.getSimpleSceneVo(cameraDetail);
             if(voList .size() <=0){
@@ -265,8 +268,8 @@ public class SceneProServiceImpl extends ServiceImpl<ISceneProMapper, ScenePro>
                 log.info("lockOrUnLockBySpace---cameraId:{},totalSpace:{},useSpace{},space:{},payStatus:{}", cameraId,totalSpace,usedSpace,space,1);
                 lockOrUnLockScenes(lockedIds,1,cameraType);
             }
+            log.info("异步任务执行,当前线程:" + Thread.currentThread().getName()+"执行完毕");
         });
-        log.info("异步任务执行,当前线程:" + Thread.currentThread().getName()+"执行完毕");
 
     }
 
@@ -652,6 +655,7 @@ public class SceneProServiceImpl extends ServiceImpl<ISceneProMapper, ScenePro>
         }
         Long cameraId = scenePro == null ? scenePlus.getCameraId() : scenePro.getCameraId();
         Long userId = scenePro == null ? scenePlus.getUserId() :scenePro.getUserId();
+        Integer status = scenePro == null ? scenePlus.getSceneStatus() :scenePro.getStatus();
         // 判断是否有绑定会员权益
         Long count = userIncrementService.getValidCountByCameraId(cameraId);
         if(count <= 0){
@@ -660,6 +664,9 @@ public class SceneProServiceImpl extends ServiceImpl<ISceneProMapper, ScenePro>
         if(userId == null){
             throw new BusinessException(SceneConstant.FAILURE_CODE_5013, SceneConstant.FAILURE_MSG_5013);
         }
+        if(status !=-2){
+            throw new BusinessException(SceneConstant.FAILURE_CODE_5033, SceneConstant.FAILURE_MSG_5033);
+        }
         //只能复制自己的场景
         User user = userService.getByUserName(userName);
         if(user == null || !user.getId().equals(userId) ){