Ver código fonte

1/31 刷新专利法律事务

lwhhszx 1 ano atrás
pai
commit
ddedd18cdc

+ 20 - 0
src/main/java/cn/cslg/pas/common/config/ThreadPoolConfig.java

@@ -0,0 +1,20 @@
+package cn.cslg.pas.common.config;
+
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;  
+import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;  
+  
+@Configuration  
+public class ThreadPoolConfig {  
+  
+    @Bean  
+    public ThreadPoolTaskExecutor threadPoolTaskExecutor() {  
+        ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();  
+        executor.setCorePoolSize(5); // 设置核心线程数  
+        executor.setMaxPoolSize(5); // 设置最大线程数
+        executor.setQueueCapacity(25); // 设置队列容量  
+        executor.setThreadNamePrefix("my-thread-pool-"); // 设置线程名称前缀  
+        executor.initialize(); // 初始化线程池  
+        return executor;  
+    }  
+}

+ 29 - 4
src/main/java/cn/cslg/pas/service/business/EventService.java

@@ -271,8 +271,8 @@ public class EventService extends ServiceImpl<EventMapper, Event> implements Bus
 
         //返回分组数据
         QueryGroupImp queryGroupImp = queryGroupFactory.getClass(groupConfig.getGroupClass());
-        String countFiled ="id";
-        ReGroupDataVO reGroupDataVO = queryGroupImp.getGroup(sqls, tableName, groupConfig.getSqlField(),countFiled);
+        String countFiled = "id";
+        ReGroupDataVO reGroupDataVO = queryGroupImp.getGroup(sqls, tableName, groupConfig.getSqlField(), countFiled);
 
         //装载数据
         GroupVO groupVO = new GroupVO();
@@ -460,9 +460,9 @@ public class EventService extends ServiceImpl<EventMapper, Event> implements Bus
             rootSql = "(tenant_id =" + tenant_id + ")";
         }
 
-        if (sqls.get(0) != null && !sqls.get(0).equals("")&&!rootSql.equals("")) {
+        if (sqls.get(0) != null && !sqls.get(0).equals("") && !rootSql.equals("")) {
             sqls.set(0, rootSql + " and" + "(" + sqls.get(0) + ")");
-        } else if((sqls.get(0) == null ||sqls.get(0).equals(""))&&!rootSql.equals("")){
+        } else if ((sqls.get(0) == null || sqls.get(0).equals("")) && !rootSql.equals("")) {
             sqls.set(0, rootSql);
         }
 
@@ -470,4 +470,29 @@ public class EventService extends ServiceImpl<EventMapper, Event> implements Bus
 
     }
 
+    /**
+     * 参数检查
+     * @param object
+     */
+    public void checkParameter(Object object) {
+          String name =null;
+          Integer id =null;
+          Integer scenarioId =null;
+        if (object instanceof EventDTO) {
+            EventDTO eventDTO = (EventDTO) object;
+               eventDTO.getScenarioId();
+               name =eventDTO.getName();
+               scenarioId =eventDTO.getScenarioId();
+        }
+        else if(object instanceof UpdateEventDTO)
+        {
+            UpdateEventDTO eventDTO = (UpdateEventDTO) object;
+            eventDTO.getScenarioId();
+            name =eventDTO.getName();
+            scenarioId =eventDTO.getScenarioId();
+            id =eventDTO.getId();
+        }
+
+
+    }
 }

+ 6 - 5
src/main/java/cn/cslg/pas/service/business/es/EsService.java

@@ -284,7 +284,7 @@ public class EsService {
                         BeanUtils.copyProperties(patent1, columnDTO);
                         if (projectId != null) {
                             try {
-                                columnDTO.setMergeApplicant(esPatentService.getMergeApp(projectId,id));
+                                columnDTO.setMergeApplicant(esPatentService.getMergeApp(projectId, id));
                             } catch (IOException e) {
                                 columnDTO.setMergeApplicant(new ArrayList<>());
                             }
@@ -317,7 +317,7 @@ public class EsService {
                 BeanUtils.copyProperties(esMess, columnDTO);
                 if (projectId != null) {
                     try {
-                        columnDTO.setMergeApplicant(esPatentService.getMergeApp(projectId,id));
+                        columnDTO.setMergeApplicant(esPatentService.getMergeApp(projectId, id));
                     } catch (IOException e) {
                         columnDTO.setMergeApplicant(new ArrayList<>());
                     }
@@ -493,6 +493,7 @@ public class EsService {
             return -1;
         }
     }
+
     //更新patent
     public Integer updatePatentById(Patent patent, String id) {
         UpdateRequest<Patent, Patent> req;
@@ -827,7 +828,7 @@ public class EsService {
         req = UpdateRequest.of(
                 b -> b.index("legal_event")
                         .id(id)
-                        .doc(legalEvent)
+                        .doc(legalEvent).refresh(Refresh.True).waitForActiveShards(WaitForActiveShards.of(i -> i.count(1)))
         );
         try {
             client.update(req, LegalEvent.class);
@@ -847,7 +848,7 @@ public class EsService {
     public String addLegalEvent(LegalEvent legalEvent) throws Exception {
         IndexResponse indexResponse = client.index(i -> i
                 .index("legal_event")
-                .document(legalEvent)
+                .document(legalEvent).refresh(Refresh.True).waitForActiveShards(WaitForActiveShards.of(t -> t.count(1)))
         );
         return indexResponse.id();
 
@@ -1038,7 +1039,7 @@ public class EsService {
                     legalEvent1.setDescription(item.getLegalStatusInfo());
                     legalEvent1.setName(item.getLegalStatus());
                     try {
-                   String reId =this.addLegalEvent(legalEvent1);
+                        String reId = this.addLegalEvent(legalEvent1);
                     } catch (Exception e) {
                         throw new XiaoShiException(e.getMessage());
                     }

+ 5 - 3
src/main/java/cn/cslg/pas/service/importPatent/ImportFromWebToEsService.java

@@ -301,9 +301,11 @@ public class ImportFromWebToEsService implements PatentImportImp {
 
 
     public void setPatentToEsProductAll() {
-        importTaskAMVO.setMessageThreadDoneCounter(importTaskAMVO.getThreadDoneCounter() + 1);
-        if (importTaskAMVO.getMessageThreadCounter().equals(importTaskAMVO.getMessageThreadDoneCounter())) {
-            savePatentToEsThread.setIfProductAll(true);
+        synchronized ("装载专利信息") {
+            importTaskAMVO.setMessageThreadDoneCounter(importTaskAMVO.getMessageThreadDoneCounter() + 1);
+            if (importTaskAMVO.getMessageThreadCounter().equals(importTaskAMVO.getMessageThreadDoneCounter())) {
+                savePatentToEsThread.setIfProductAll(true);
+            }
         }
     }
 

+ 3 - 0
src/main/java/cn/cslg/pas/service/importPatent/SavePatentToEsThread.java

@@ -129,6 +129,7 @@ public class SavePatentToEsThread extends Thread {
             }
         }
         taskThread.awakeTaskThread();
+        System.out.println("专利信息装载完毕");
     }
 
     public SavePatentToEsThread(TaskThread taskThread, ApplicationContext applicationContext) {
@@ -150,7 +151,9 @@ public class SavePatentToEsThread extends Thread {
     public void setIfProductAll(Boolean ifProductAll) {
 
         this.ifProductAll = ifProductAll;
+        System.out.println("专利导入全部结束"+ this.ifProductAll);
         if (taskLock.tryLock()) {
+            System.out.println("专利导入到es解锁");
             taskCondition.signalAll();
             taskLock.unlock();
         }

+ 15 - 10
src/main/java/cn/cslg/pas/service/importPatent/SchedulingTaskService.java

@@ -13,6 +13,7 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.context.ApplicationContext;
+import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
 import org.springframework.stereotype.Service;
 
 import java.util.ArrayList;
@@ -29,8 +30,8 @@ public class SchedulingTaskService {
 
     @Autowired
     private ApplicationContext applicationContext;
-    private ThreadPoolExecutor executor = (ThreadPoolExecutor) Executors.newFixedThreadPool(Constants.MAX_IMPORT_TASK_COUNT);
-
+    @Autowired
+    private ThreadPoolTaskExecutor threadPoolTaskExecutor;
     @Autowired
     private ImportTaskConditionService importTaskConditionService;
 
@@ -39,8 +40,10 @@ public class SchedulingTaskService {
     private List<ImportTaskAMVO> importTaskAMVOS;
 
     public void startTask() {
-        Integer freeCount = Constants.MAX_IMPORT_TASK_COUNT - executor.getActiveCount();
-
+        Integer freeCount = Constants.MAX_IMPORT_TASK_COUNT - threadPoolTaskExecutor.getActiveCount();
+       if(importTaskAMVOS==null){
+           importTaskAMVOS=new ArrayList<>();
+       }
         // 当正在活跃的线程数小于最大线程数时
         if (freeCount > 0) {
             //查找任务
@@ -55,17 +58,19 @@ public class SchedulingTaskService {
 
             if (importTaskList.size() > 0) {
                 // 装载任务信息
-                importTaskAMVOS = this.loadTaskAMVOS(importTaskList);
+             List<ImportTaskAMVO>   importTaskAMVOFromDbs = this.loadTaskAMVOS(importTaskList);
 
-                for (int i = 0; i < importTaskAMVOS.size(); i++) {
+                for (int i = 0; i < importTaskAMVOFromDbs.size(); i++) {
                     importTaskList.get(i).setState(1);
                     importTaskList.get(i).updateById();
-                    importTaskAMVOS.get(i).setState(1);
-                    importTaskAMVOS.get(i).setThreadCounter(0);
-                    TaskThread taskThread = new TaskThread(importTaskAMVOS.get(i), applicationContext);
-                    executor.execute(taskThread);
+                    importTaskAMVOFromDbs.get(i).setState(1);
+                    importTaskAMVOFromDbs.get(i).setThreadCounter(0);
+                    TaskThread taskThread = new TaskThread(importTaskAMVOFromDbs.get(i), applicationContext);
+                    threadPoolTaskExecutor.execute(taskThread);
+                    importTaskAMVOS.add(importTaskAMVOFromDbs.get(i));
                 }
 
+
             }
 
         }

+ 15 - 0
src/main/java/cn/cslg/pas/service/importPatent/TaskExecutor.java

@@ -0,0 +1,15 @@
+package cn.cslg.pas.service.importPatent;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;  
+import org.springframework.stereotype.Component;  
+  
+@Component  
+public class TaskExecutor {  
+
+    private ThreadPoolTaskExecutor threadPoolTaskExecutor;  
+  
+    public void executeTask(Runnable task) {  
+        threadPoolTaskExecutor.execute(task);  
+    }  
+}

+ 1 - 0
src/main/java/cn/cslg/pas/service/importPatent/TaskThread.java

@@ -144,6 +144,7 @@ public class TaskThread extends Thread {
     public void awakeTaskThread() {
         synchronized ("导入任务是否完成") {
             importTaskAMVO.setThreadDoneCounter(importTaskAMVO.getThreadDoneCounter() + 1);
+            System.out.println("任务已经完成第"+importTaskAMVO.getThreadDoneCounter());
             if (importTaskAMVO.getThreadCounter().equals(importTaskAMVO.getThreadDoneCounter())) {
 
                 System.out.println("任务已经完成");

+ 3 - 5
src/test/java/cn/cslg/pas/service/CommonServiceTests.java

@@ -137,10 +137,8 @@ public class CommonServiceTests {
 //李仁杰<2232723707@qq.com>"
     @Test
     public void testEmail() throws Exception{
- Map<String,List<String>> map =new HashMap<>();
- map.put("a",new ArrayList<>());
- List<String> aa =map.get("a");
- aa.add("111");
- System.out.println(aa);
+        String te = "201100 上海市闵行区园美路58号1幢2层203、204室";
+        te+="aaaa";
+ System.out.println(te);
     }
     }