|
|
|
@ -18,6 +18,7 @@ import java.util.ArrayList; |
|
|
|
import java.util.HashMap; |
|
|
|
import java.util.List; |
|
|
|
import java.util.Map; |
|
|
|
import java.util.concurrent.*; |
|
|
|
|
|
|
|
@Service |
|
|
|
public class DepositoryServiceImpl implements DepositoryService { |
|
|
|
@ -343,12 +344,34 @@ public class DepositoryServiceImpl implements DepositoryService { |
|
|
|
Map<String, Object> param = new HashMap<>(); |
|
|
|
param.put("parentId", 0); |
|
|
|
List<Depository> depositories = depositoryMapper.findDepositoryRecordPByCondition(param); |
|
|
|
|
|
|
|
// 开启对应数量的线程
|
|
|
|
ExecutorService exs = Executors.newFixedThreadPool(depositories.size()); |
|
|
|
// 结果集
|
|
|
|
List<Object> list = new ArrayList<>(); |
|
|
|
List<Future<Object>> futureList = new ArrayList<Future<Object>>(); |
|
|
|
|
|
|
|
// 1.定义CompletionService
|
|
|
|
CompletionService<Object> completionService = new ExecutorCompletionService<Object>(exs); |
|
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < depositories.size(); i++) { |
|
|
|
Depository d = depositories.get(i); |
|
|
|
List<Object> childForMaterialTypeByParent = findChildForDepositoryByParent(d.getId(), ""); |
|
|
|
Map<String, Object> stringObjectMap = InitTreeMenus2(d, childForMaterialTypeByParent); |
|
|
|
list.add(stringObjectMap); |
|
|
|
Future<Object> future = completionService.submit(new Task(d,"")); |
|
|
|
futureList.add(future); |
|
|
|
} |
|
|
|
|
|
|
|
// 3.获取结果
|
|
|
|
for(int i=0;i<depositories.size();i++){ |
|
|
|
Object result = null; |
|
|
|
try { |
|
|
|
result = completionService.take().get(); |
|
|
|
} catch (InterruptedException e) { |
|
|
|
e.printStackTrace(); |
|
|
|
} catch (ExecutionException e) { |
|
|
|
e.printStackTrace(); |
|
|
|
} |
|
|
|
list.add(result); |
|
|
|
} |
|
|
|
return list; |
|
|
|
} |
|
|
|
@ -366,16 +389,54 @@ public class DepositoryServiceImpl implements DepositoryService { |
|
|
|
param.put("adminorg", 361); |
|
|
|
List<Depository> depositories = depositoryMapper.findDepositoryRecordPByCondition(param); |
|
|
|
List<Object> list = new ArrayList<>(); |
|
|
|
|
|
|
|
// 开启对应数量的线程
|
|
|
|
ExecutorService exs = Executors.newFixedThreadPool(depositories.size()); |
|
|
|
// 结果集
|
|
|
|
List<Future<Object>> futureList = new ArrayList<Future<Object>>(); |
|
|
|
|
|
|
|
// 1.定义CompletionService
|
|
|
|
CompletionService<Object> completionService = new ExecutorCompletionService<Object>(exs); |
|
|
|
for (int i = 0; i < depositories.size(); i++) { |
|
|
|
Depository d = depositories.get(i); |
|
|
|
List<Object> childForMaterialTypeByParent = findChildForDepositoryByParent(d.getId(), adminorg); |
|
|
|
Map<String, Object> stringObjectMap = InitTreeMenus2(d, childForMaterialTypeByParent); |
|
|
|
list.add(stringObjectMap); |
|
|
|
Future<Object> future = completionService.submit(new Task(d,adminorg)); |
|
|
|
futureList.add(future); |
|
|
|
} |
|
|
|
|
|
|
|
// 3.获取结果
|
|
|
|
for(int i=0;i<depositories.size();i++){ |
|
|
|
Object result = null; |
|
|
|
try { |
|
|
|
result = completionService.take().get(); |
|
|
|
} catch (InterruptedException e) { |
|
|
|
e.printStackTrace(); |
|
|
|
} catch (ExecutionException e) { |
|
|
|
e.printStackTrace(); |
|
|
|
} |
|
|
|
list.add(result); |
|
|
|
} |
|
|
|
return list; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 用于执行线程任务
|
|
|
|
class Task implements Callable<Object> { |
|
|
|
|
|
|
|
Depository d; |
|
|
|
String adminorg; |
|
|
|
|
|
|
|
public Task(Depository d,String adminorg){ |
|
|
|
this.d = d; |
|
|
|
this.adminorg = adminorg; |
|
|
|
} |
|
|
|
@Override |
|
|
|
public Object call() throws Exception { |
|
|
|
List<Object> childForMaterialTypeByParent = findChildForDepositoryByParent(d.getId(), adminorg); |
|
|
|
Map<String, Object> stringObjectMap = InitTreeMenus2(d, childForMaterialTypeByParent); |
|
|
|
return stringObjectMap; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 获取当前部门以及公共仓库 |
|
|
|
* |
|
|
|
|