diff --git a/jeelowcode-core/src/main/java/com/jeelowcode/core/framework/config/btncommand/receiver/ButtonReceiverBase.java b/jeelowcode-core/src/main/java/com/jeelowcode/core/framework/config/btncommand/receiver/ButtonReceiverBase.java index 148e519..e1e6aec 100644 --- a/jeelowcode-core/src/main/java/com/jeelowcode/core/framework/config/btncommand/receiver/ButtonReceiverBase.java +++ b/jeelowcode-core/src/main/java/com/jeelowcode/core/framework/config/btncommand/receiver/ButtonReceiverBase.java @@ -28,10 +28,12 @@ import com.jeelowcode.core.framework.mapper.FormFieldWebMapper; import com.jeelowcode.core.framework.params.model.WebFormatConfigModel; import com.jeelowcode.core.framework.service.IFormService; import com.jeelowcode.core.framework.utils.Func; +import com.jeelowcode.framework.utils.utils.FuncBase; import org.apache.commons.collections4.map.LinkedMap; import java.util.*; import java.util.concurrent.ExecutionException; +import java.util.concurrent.ForkJoinPool; import java.util.stream.Collectors; /** @@ -81,8 +83,10 @@ public class ButtonReceiverBase { Set webViewFieldSet = new HashSet<>(formService.getWebViewFieldList(dbFormId)); Map finalRoleDisableMap = roleDisableMap; + ForkJoinPool pool = null; try { - Func.jeelowcodeForkJoinPool().submit(() -> records.parallelStream().forEach(recordMap -> recordMap.keySet().removeIf(key -> { + pool = FuncBase.jeelowcodeForkJoinPool(); + pool.submit(() -> records.parallelStream().forEach(recordMap -> recordMap.keySet().removeIf(key -> { if(Func.equals(key,"jeelowcode_subtable_data") || Func.equals(key,"hasChildren") || Func.equals(key,"leaf")){ return false; } @@ -98,6 +102,10 @@ public class ButtonReceiverBase { }))).get(); } catch (InterruptedException | ExecutionException e) { throw new RuntimeException(e.getMessage()); + } finally { + if (pool != null) { + pool.shutdown(); + } } } diff --git a/jeelowcode-core/src/main/java/com/jeelowcode/core/framework/controller/BaseController.java b/jeelowcode-core/src/main/java/com/jeelowcode/core/framework/controller/BaseController.java index 23084ed..22b035c 100644 --- a/jeelowcode-core/src/main/java/com/jeelowcode/core/framework/controller/BaseController.java +++ b/jeelowcode-core/src/main/java/com/jeelowcode/core/framework/controller/BaseController.java @@ -32,11 +32,13 @@ import com.jeelowcode.framework.utils.model.ExecuteEnhanceModel; import com.jeelowcode.framework.utils.model.ResultDataModel; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.jeelowcode.framework.utils.utils.FuncBase; import io.swagger.v3.oas.annotations.tags.Tag; import java.util.List; import java.util.Map; import java.util.concurrent.ExecutionException; +import java.util.concurrent.ForkJoinPool; @Tag(name = "低代码框架-公共框架接口") public class BaseController { @@ -326,8 +328,10 @@ public class BaseController { protected void formatFormEntityPageVo(List records, IFormService dbFormService){ + ForkJoinPool pool = null; try { - Func.jeelowcodeForkJoinPool().submit(() -> records.parallelStream().forEach(vo ->{ + pool = FuncBase.jeelowcodeForkJoinPool(); + pool.submit(() -> records.parallelStream().forEach(vo ->{ Map couMap = dbFormService.getFormCou(vo.getId()); Integer js_cou = Func.getMap2IntDefault(couMap, "js_cou",0); Integer scss_cou = Func.getMap2IntDefault(couMap, "scss_cou",0); @@ -345,6 +349,10 @@ public class BaseController { })).get(); } catch (InterruptedException | ExecutionException e) { throw new RuntimeException(e.getMessage()); + } finally { + if (pool != null) { + pool.shutdown(); + } } } diff --git a/jeelowcode-core/src/main/java/com/jeelowcode/core/framework/controller/DbFormController.java b/jeelowcode-core/src/main/java/com/jeelowcode/core/framework/controller/DbFormController.java index 49ed921..7cf344e 100644 --- a/jeelowcode-core/src/main/java/com/jeelowcode/core/framework/controller/DbFormController.java +++ b/jeelowcode-core/src/main/java/com/jeelowcode/core/framework/controller/DbFormController.java @@ -66,6 +66,7 @@ import java.util.List; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ExecutionException; +import java.util.concurrent.ForkJoinPool; import java.util.stream.Collectors; @Tag(name = "低代码框架-框架接口") @@ -232,8 +233,10 @@ public class DbFormController extends BaseController { } Map>> resultMap = new ConcurrentHashMap<>(); + ForkJoinPool pool = null; try { - Func.jeelowcodeForkJoinPool().submit(() -> labelParamList.parallelStream().forEach(labelParam ->{ + pool = FuncBase.jeelowcodeForkJoinPool(); + pool.submit(() -> labelParamList.parallelStream().forEach(labelParam ->{ Long dbformId = labelParam.getDbformId(); List fieldList = labelParam.getFieldList(); String code = labelParam.getCode(); @@ -279,6 +282,10 @@ public class DbFormController extends BaseController { })).get(); } catch (InterruptedException | ExecutionException e) { throw new RuntimeException(e.getMessage()); + } finally { + if (pool != null) { + pool.shutdown(); + } } return BaseWebResult.success(resultMap); diff --git a/jeelowcode-core/src/main/java/com/jeelowcode/core/framework/controller/ReportDataController.java b/jeelowcode-core/src/main/java/com/jeelowcode/core/framework/controller/ReportDataController.java index 9212dae..7bba94d 100644 --- a/jeelowcode-core/src/main/java/com/jeelowcode/core/framework/controller/ReportDataController.java +++ b/jeelowcode-core/src/main/java/com/jeelowcode/core/framework/controller/ReportDataController.java @@ -20,6 +20,7 @@ import com.jeelowcode.core.framework.utils.Func; import com.jeelowcode.core.framework.utils.FuncWeb; import com.jeelowcode.framework.exception.JeeLowCodeException; import com.jeelowcode.framework.utils.model.ResultDataModel; +import com.jeelowcode.framework.utils.utils.FuncBase; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.tags.Tag; import lombok.AllArgsConstructor; @@ -59,8 +60,10 @@ public class ReportDataController extends BaseController { Map params = FuncWeb.getParameterBodyMap(req); List reportCodeList = Func.toStrList(reportCodeListStr); Map resultMap = new ConcurrentHashMap<>(); + ForkJoinPool pool = null; try { - Func.jeelowcodeForkJoinPool().submit(() -> reportCodeList.parallelStream().forEach(reportCode -> { + pool = FuncBase.jeelowcodeForkJoinPool(); + pool.submit(() -> reportCodeList.parallelStream().forEach(reportCode -> { // 处理代码 Map subParam = (Map) params.get(reportCode); if (Func.isEmpty(subParam)) { @@ -71,6 +74,10 @@ public class ReportDataController extends BaseController { })).get(); } catch (InterruptedException | ExecutionException e) { throw new RuntimeException(e.getMessage()); + } finally { + if (pool != null) { + pool.shutdown(); + } } return BaseWebResult.success(resultMap); } diff --git a/jeelowcode-core/src/main/java/com/jeelowcode/core/framework/service/impl/FrameServiceImpl.java b/jeelowcode-core/src/main/java/com/jeelowcode/core/framework/service/impl/FrameServiceImpl.java index 4d96e31..a19d7d8 100644 --- a/jeelowcode-core/src/main/java/com/jeelowcode/core/framework/service/impl/FrameServiceImpl.java +++ b/jeelowcode-core/src/main/java/com/jeelowcode/core/framework/service/impl/FrameServiceImpl.java @@ -62,6 +62,7 @@ import org.springframework.transaction.annotation.Transactional; import java.util.*; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ExecutionException; +import java.util.concurrent.ForkJoinPool; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicReference; import java.util.stream.Collectors; @@ -363,8 +364,10 @@ public class FrameServiceImpl implements IFrameService { if (Func.isNotEmpty(summaryTopList)) { Map topMap = new ConcurrentHashMap(); //并行流处理 + ForkJoinPool pool = null; try { - Func.jeelowcodeForkJoinPool().submit(() -> summaryTopList.parallelStream().forEach(summaryEntity -> { + pool = FuncBase.jeelowcodeForkJoinPool(); + pool.submit(() -> summaryTopList.parallelStream().forEach(summaryEntity -> { Long id = summaryEntity.getId(); String summarySql = summaryEntity.getSummarySql(); String summaryLabel = summaryEntity.getSummaryLabel(); @@ -396,6 +399,10 @@ public class FrameServiceImpl implements IFrameService { })).get(); } catch (InterruptedException | ExecutionException e) { throw new RuntimeException(e.getMessage()); + } finally { + if (pool != null) { + pool.shutdown(); + } } //按顺序取出来 summaryTopList.stream().forEach(summaryEntity -> { @@ -566,8 +573,10 @@ public class FrameServiceImpl implements IFrameService { AtomicReference importState = new AtomicReference<>(1);//成功 String redisKey = "excel:import:task_" + fieldId;//判断是否 AtomicReference breakFlag = new AtomicReference<>(false); + ForkJoinPool pool = null; try { - Func.jeelowcodeForkJoinPool().submit(() -> entityList.parallelStream().forEach(entity -> { + pool = FuncBase.jeelowcodeForkJoinPool(); + pool.submit(() -> entityList.parallelStream().forEach(entity -> { if (breakFlag.get()) {//说明退出 return; } @@ -615,6 +624,10 @@ public class FrameServiceImpl implements IFrameService { })).get(); } catch (InterruptedException | ExecutionException e) { throw new RuntimeException(e.getMessage()); + } finally { + if (pool != null) { + pool.shutdown(); + } } //如果是取消的话,需要回滚事务 @@ -1370,8 +1383,10 @@ public class FrameServiceImpl implements IFrameService { if (Func.isEmpty(treeDataList)) { return; } + ForkJoinPool pool = null; try { - Func.jeelowcodeForkJoinPool().submit(() -> treeDataList.parallelStream().forEach(dataMap -> { + pool = FuncBase.jeelowcodeForkJoinPool(); + pool.submit(() -> treeDataList.parallelStream().forEach(dataMap -> { Long id = Func.getMap2Long(dataMap, "id"); SqlInfoQueryWrapper.Wrapper wrapper = SqlHelper.getQueryWrapper() @@ -1388,6 +1403,10 @@ public class FrameServiceImpl implements IFrameService { })).get(); } catch (InterruptedException | ExecutionException e) { throw new RuntimeException(e.getMessage()); + } finally { + if (pool != null) { + pool.shutdown(); + } } } diff --git a/jeelowcode-core/src/main/java/com/jeelowcode/core/framework/utils/Func.java b/jeelowcode-core/src/main/java/com/jeelowcode/core/framework/utils/Func.java index 249c9bb..fec0c10 100644 --- a/jeelowcode-core/src/main/java/com/jeelowcode/core/framework/utils/Func.java +++ b/jeelowcode-core/src/main/java/com/jeelowcode/core/framework/utils/Func.java @@ -459,12 +459,18 @@ public class Func extends FuncBase { public static void handlePlusDataList(List> records, Map fieldTypeEnumMap) { + ForkJoinPool pool = null; try { - Func.jeelowcodeForkJoinPool().submit(() -> records.parallelStream().forEach(recordMap -> { + pool = FuncBase.jeelowcodeForkJoinPool(); + pool.submit(() -> records.parallelStream().forEach(recordMap -> { handlePlusDataMap(recordMap, fieldTypeEnumMap); })).get(); } catch (InterruptedException | ExecutionException e) { throw new RuntimeException(e.getMessage()); + } finally { + if (pool != null) { + pool.shutdown(); + } } } diff --git a/jeelowcode-framework/jeelowcode-utils/src/main/java/com/jeelowcode/framework/utils/component/defaultval/DefaultValAspect.java b/jeelowcode-framework/jeelowcode-utils/src/main/java/com/jeelowcode/framework/utils/component/defaultval/DefaultValAspect.java index 21f0762..486d8ae 100644 --- a/jeelowcode-framework/jeelowcode-utils/src/main/java/com/jeelowcode/framework/utils/component/defaultval/DefaultValAspect.java +++ b/jeelowcode-framework/jeelowcode-utils/src/main/java/com/jeelowcode/framework/utils/component/defaultval/DefaultValAspect.java @@ -31,6 +31,8 @@ import java.time.LocalDateTime; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.ForkJoinPool; /** * 默认值切面 @@ -180,7 +182,7 @@ public class DefaultValAspect { } // plus批量新增 - private void saveBatchPlus(Object[] args) throws Throwable { + private void saveBatchPlus(Object[] args) { List list = (List) args[0]; Object o = list.get(0); if (!(o instanceof BaseEntity || o instanceof BaseTenantEntity)) {//不属于我们的类型 @@ -192,33 +194,43 @@ public class DefaultValAspect { Long tenantId = proxyAdapter.getTenantId(); Long deptId = proxyAdapter.getOnlineUserDeptId(); - FuncBase.jeelowcodeForkJoinPool().submit(() -> list.parallelStream().forEach(obj -> { - //基本类 - if (obj instanceof BaseEntity) {//我们自定义的实体 - BaseEntity baseEntity = (BaseEntity) obj; - Long createUser = baseEntity.getCreateUser(); - Long createDept = baseEntity.getCreateDept(); + ForkJoinPool pool = null; + try { + pool = FuncBase.jeelowcodeForkJoinPool(); + pool.submit(() -> list.parallelStream().forEach(obj -> { + //基本类 + if (obj instanceof BaseEntity) {//我们自定义的实体 + BaseEntity baseEntity = (BaseEntity) obj; + Long createUser = baseEntity.getCreateUser(); + Long createDept = baseEntity.getCreateDept(); - if (FuncBase.isNotEmpty(current)) { - baseEntity.setCreateTime(current); + if (FuncBase.isNotEmpty(current)) { + baseEntity.setCreateTime(current); + } + if (FuncBase.isNotEmpty(userId) && FuncBase.isEmpty(createUser)) { + baseEntity.setCreateUser(userId); + } + if (FuncBase.isNotEmpty(deptId) && FuncBase.isEmpty(createDept)) { + baseEntity.setCreateDept(deptId); + } } - if (FuncBase.isNotEmpty(userId) && FuncBase.isEmpty(createUser)) { - baseEntity.setCreateUser(userId); - } - if (FuncBase.isNotEmpty(deptId) && FuncBase.isEmpty(createDept)) { - baseEntity.setCreateDept(deptId); + + if (obj instanceof BaseTenantEntity) {//我们自定义的实体 + BaseTenantEntity baseEntity = (BaseTenantEntity) obj; + Long selectTenantId = baseEntity.getTenantId(); + + if (FuncBase.isEmpty(selectTenantId) && FuncBase.isNotEmpty(tenantId)) { + baseEntity.setTenantId(tenantId); + } } + })).get(); + } catch (InterruptedException | ExecutionException e){ + throw new RuntimeException(e.getMessage()); + } finally { + if (pool != null) { + pool.shutdown(); } - - if (obj instanceof BaseTenantEntity) {//我们自定义的实体 - BaseTenantEntity baseEntity = (BaseTenantEntity) obj; - Long selectTenantId = baseEntity.getTenantId(); - - if (FuncBase.isEmpty(selectTenantId) && FuncBase.isNotEmpty(tenantId)) { - baseEntity.setTenantId(tenantId); - } - } - })).get(); + } } // plus新增修改 @@ -269,7 +281,7 @@ public class DefaultValAspect { } // plus批量新增修改 - private void saveOrUpdateBatchPlus(Object[] args) throws Throwable { + private void saveOrUpdateBatchPlus(Object[] args) { List list = (List) args[0]; Object o = list.get(0); if (!(o instanceof BaseEntity || o instanceof BaseTenantEntity)) {//不属于我们的类型 @@ -281,41 +293,51 @@ public class DefaultValAspect { Long tenantId = proxyAdapter.getTenantId(); Long deptId = proxyAdapter.getOnlineUserDeptId(); - FuncBase.jeelowcodeForkJoinPool().submit(() -> list.parallelStream().forEach(obj -> { - //基本类 - if (obj instanceof BaseEntity) {//我们自定义的实体 - BaseEntity baseEntity = (BaseEntity) obj; - if (FuncBase.isEmpty(baseEntity.getId())) { - Long createUser = baseEntity.getCreateUser(); - Long createDept = baseEntity.getCreateDept(); - if (FuncBase.isNotEmpty(current)) { - baseEntity.setCreateTime(current); - } - if (FuncBase.isNotEmpty(userId) && FuncBase.isEmpty(createUser)) { - baseEntity.setCreateUser(userId); - } - if (FuncBase.isNotEmpty(deptId) && FuncBase.isEmpty(createDept)) { - baseEntity.setCreateDept(deptId); - } - } else { - baseEntity.setUpdateTime(current); - if (FuncBase.isEmpty(baseEntity.getUpdateUser()) && FuncBase.isNotEmpty(userId)) { - baseEntity.setUpdateUser(userId); + ForkJoinPool pool = null; + try { + pool = FuncBase.jeelowcodeForkJoinPool(); + pool.submit(() -> list.parallelStream().forEach(obj -> { + //基本类 + if (obj instanceof BaseEntity) {//我们自定义的实体 + BaseEntity baseEntity = (BaseEntity) obj; + if (FuncBase.isEmpty(baseEntity.getId())) { + Long createUser = baseEntity.getCreateUser(); + Long createDept = baseEntity.getCreateDept(); + if (FuncBase.isNotEmpty(current)) { + baseEntity.setCreateTime(current); + } + if (FuncBase.isNotEmpty(userId) && FuncBase.isEmpty(createUser)) { + baseEntity.setCreateUser(userId); + } + if (FuncBase.isNotEmpty(deptId) && FuncBase.isEmpty(createDept)) { + baseEntity.setCreateDept(deptId); + } + } else { + baseEntity.setUpdateTime(current); + if (FuncBase.isEmpty(baseEntity.getUpdateUser()) && FuncBase.isNotEmpty(userId)) { + baseEntity.setUpdateUser(userId); + } } } - } - if (obj instanceof BaseTenantEntity) {//我们自定义的实体 - BaseTenantEntity baseEntity = (BaseTenantEntity) obj; - if (FuncBase.isNotEmpty(baseEntity.getId())){ - return; - } - Long selectTenantId = baseEntity.getTenantId(); - if (FuncBase.isEmpty(selectTenantId) && FuncBase.isNotEmpty(tenantId)) { - baseEntity.setTenantId(tenantId); + if (obj instanceof BaseTenantEntity) {//我们自定义的实体 + BaseTenantEntity baseEntity = (BaseTenantEntity) obj; + if (FuncBase.isNotEmpty(baseEntity.getId())){ + return; + } + Long selectTenantId = baseEntity.getTenantId(); + if (FuncBase.isEmpty(selectTenantId) && FuncBase.isNotEmpty(tenantId)) { + baseEntity.setTenantId(tenantId); + } } + })).get(); + } catch (InterruptedException | ExecutionException e){ + throw new RuntimeException(e.getMessage()); + } finally { + if (pool != null) { + pool.shutdown(); } - })).get(); + } } //编辑