From fa3ec77225c230a44e107cd188d26e1d974d8029 Mon Sep 17 00:00:00 2001
From: 田源 <lastanimals@163.com>
Date: 星期五, 05 一月 2024 15:59:43 +0800
Subject: [PATCH] 整合代码
---
Source/UBCS/ubcs-service/ubcs-code/src/main/java/com/vci/ubcs/code/service/impl/MdmIOServiceImpl.java | 108 +++++++++++++++++++++++++++++------------------------
1 files changed, 59 insertions(+), 49 deletions(-)
diff --git a/Source/UBCS/ubcs-service/ubcs-code/src/main/java/com/vci/ubcs/code/service/impl/MdmIOServiceImpl.java b/Source/UBCS/ubcs-service/ubcs-code/src/main/java/com/vci/ubcs/code/service/impl/MdmIOServiceImpl.java
index 6f47399..67fe60b 100644
--- a/Source/UBCS/ubcs-service/ubcs-code/src/main/java/com/vci/ubcs/code/service/impl/MdmIOServiceImpl.java
+++ b/Source/UBCS/ubcs-service/ubcs-code/src/main/java/com/vci/ubcs/code/service/impl/MdmIOServiceImpl.java
@@ -87,6 +87,7 @@
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.CopyOnWriteArraySet;
+import java.util.concurrent.ForkJoinPool;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.stream.Collectors;
@@ -201,6 +202,11 @@
* 瀹㈡埛鐜板満excel涓鸿�佺増鏈紝瀵煎嚭鐨勬�绘暟闄愬埗涓�65535
*/
public static final int EXPORT_LIMIT = 65535;
+
+ /**
+ * 鑷畾涔夊苟鍙慒orkJoinPool
+ */
+ private static final ForkJoinPool customForkJoinPool = new ForkJoinPool(Runtime.getRuntime().availableProcessors()-1);
/**
* 鎵归噺鐢宠锛氶�夊彇閫変腑鍒嗙被涓嬬殑鎵�鏈夋ā鏉垮叧閿睘鎬э紝鐩镐技灞炴�э紝蹇呭~灞炴�э紝鍐欏叆execl涓�
@@ -2740,7 +2746,7 @@
//cboOidMap.put("id", QueryOptionConstant.IN + "(" + VciBaseUtil.toInSql(codeDataMap.keySet().toArray(new String[0])) + ")");
String tableName ="";
try {
- R<BtmTypeVO> r = btmTypeClient.getAllAttributeByBtmId(codeClassifyVO.getBtmTypeId());
+ R<BtmTypeVO> r = btmTypeClient.getAllAttributeByBtmId(classifyFullInfo.getTopClassifyVO().getBtmTypeId());
if(!r.isSuccess()) {
throw new Throwable(r.getMsg());
}
@@ -4393,56 +4399,60 @@
// 鏌ヨ涓嶉渶瑕佸弬涓庡叧閿睘鎬ф牎楠岀殑闄よ嚜宸变互澶栫殑鎵�鏈夊垎绫籵id
final String isParticipateCheckOids = classifyService.selectLeafByParentClassifyOid(classifyFullInfo.getTopClassifyVO().getOid(), classifyFullInfo.getCurrentClassifyVO().getOid());
final BladeUser user = AuthUtil.getUser();
- //cboList = new CopyOnWriteArrayList<>(cboList);
- // TODO:Thread limit exceeded replacing blocked 寮傚父鏄繖閮ㄥ垎浠g爜鎶涘嚭鐨�,鎵�浠ユ殏鏃跺皢parallelStream鏀规垚浜唖tream
- List<ClientBusinessObject> repeatDataMap = cboList.stream().filter(cbo -> {
- //姣忚閮藉緱鏌ヨ.濡傛灉鍏朵腑鍑虹幇浜嗛敊璇紝鎴戜滑灏辩洿鎺ユ姏鍑哄紓甯革紝鍏朵綑鐨勬樉绀�
- //VciBaseUtil.setCurrentUserSessionInfo(sessionInfo);
- Map<String, String> conditionMap = new HashMap<>();
- ketAttrMap.forEach((attrId, attrVO) -> {
- String value =cbo.getAttributeValue(attrId.toLowerCase(Locale.ROOT));
- if (value == null) {
- value = "";
- }
- value= value.replace(REQUIRED_CHAR,SPECIAL_CHAR);
- engineService.wrapperKeyAttrConditionMap(value, keyRuleVO, attrId, trim, ignoreCase, ignoreWidth, trimAll, conditionMap);
- });
- if (!CollectionUtils.isEmpty(ketAttrMap)) {
- // 娣诲姞涓嶅弬涓庡叧閿睘鎬ф牎楠岀殑鍒嗙被oid鍒ゆ柇
- if(Func.isNotBlank(isParticipateCheckOids)){
- conditionMap.put("t.codeclsfid",QueryOptionConstant.NOTIN+isParticipateCheckOids);
- }
- if(isEdit){//濡傛灉鏄洿鏀瑰垯闇�鎺掗櫎绯荤粺鏈韩
- conditionMap.put("t.id",QueryOptionConstant.NOTEQUAL+cbo.getId());
- }
- conditionMap.put("t.lastr", "1");
- conditionMap.put("t.lastv", "1");
-
- CodeTemplateAttrSqlBO sqlBO = engineService.getSqlByTemplateVO(classifyFullInfo.getTopClassifyVO().getBtmTypeId(), templateVO, conditionMap, null);
- List<String> repeatData = commonsMapper.selectList(sqlBO.getSqlId());
- if(!repeatData.isEmpty()){
- final List<Map<String,String>> newDataList = commonsMapper.queryByOnlySqlForMap(sqlBO.getSqlUnPage());
- DefaultAttrAssimtUtil.mapToLowerCase(newDataList,true);
- //List<ClientBusinessObject> newCboList=ChangeMapTOClientBusinessObjects(newDataList);
- List<BaseModel> newCboList = new ArrayList<>();
- newDataList.stream().forEach(stringStringMap -> {
- BaseModel baseModel=new BaseModel();
- DefaultAttrAssimtUtil.copplyDefaultAttrAssimt(stringStringMap,baseModel,false,user);
- baseModel.setData(stringStringMap);
- newCboList.add(baseModel);
- });
- // 娣诲姞閿欒鍊�
- String rowIndex = cbo.getAttributeValue(IMPORT_ROW_INDEX);
- errorMap.put(rowIndex, "閲嶅鐨勮褰曠紪鍙蜂负:"+repeatData.stream().collect(Collectors.joining(",")));
- if(!CollectionUtils.isEmpty(newCboList)) {
- indexTODataMap.put(cbo.getAttributeValue(IMPORT_ROW_INDEX), newCboList);
+ // TODO:Thread limit exceeded replacing blocked 寮傚父鏄繖閮ㄥ垎浠g爜鎶涘嚭鐨�
+ // ,鎵�浠ユ殏鏃跺皢parallelStream鏀规垚浜唖tream锛屾敼鎴愪簡stream涔嬪悗鍙戠幇宸ㄦ參
+ // customForkJoinPool鎺у埗骞跺彂搴�
+ List<ClientBusinessObject> finalCboList = cboList;
+ List<ClientBusinessObject> repeatDataMap = (List<ClientBusinessObject>) customForkJoinPool.submit(()->{
+ finalCboList.parallelStream().filter(cbo -> {
+ //姣忚閮藉緱鏌ヨ.濡傛灉鍏朵腑鍑虹幇浜嗛敊璇紝鎴戜滑灏辩洿鎺ユ姏鍑哄紓甯革紝鍏朵綑鐨勬樉绀�
+ //VciBaseUtil.setCurrentUserSessionInfo(sessionInfo);
+ Map<String, String> conditionMap = new HashMap<>();
+ ketAttrMap.forEach((attrId, attrVO) -> {
+ String value =cbo.getAttributeValue(attrId.toLowerCase(Locale.ROOT));
+ if (value == null) {
+ value = "";
}
+ value= value.replace(REQUIRED_CHAR,SPECIAL_CHAR);
+ engineService.wrapperKeyAttrConditionMap(value, keyRuleVO, attrId, trim, ignoreCase, ignoreWidth, trimAll, conditionMap);
+ });
+ if (!CollectionUtils.isEmpty(ketAttrMap)) {
+ // 娣诲姞涓嶅弬涓庡叧閿睘鎬ф牎楠岀殑鍒嗙被oid鍒ゆ柇
+ if(Func.isNotBlank(isParticipateCheckOids)){
+ conditionMap.put("t.codeclsfid",QueryOptionConstant.NOTIN+isParticipateCheckOids);
+ }
+ if(isEdit){//濡傛灉鏄洿鏀瑰垯闇�鎺掗櫎绯荤粺鏈韩
+ conditionMap.put("t.id",QueryOptionConstant.NOTEQUAL+cbo.getId());
+ }
+ conditionMap.put("t.lastr", "1");
+ conditionMap.put("t.lastv", "1");
+
+ CodeTemplateAttrSqlBO sqlBO = engineService.getSqlByTemplateVO(classifyFullInfo.getTopClassifyVO().getBtmTypeId(), templateVO, conditionMap, null);
+ List<String> repeatData = commonsMapper.selectList(sqlBO.getSqlId());
+ if(!repeatData.isEmpty()){
+ final List<Map<String,String>> newDataList = commonsMapper.queryByOnlySqlForMap(sqlBO.getSqlUnPage());
+ DefaultAttrAssimtUtil.mapToLowerCase(newDataList,true);
+ //List<ClientBusinessObject> newCboList=ChangeMapTOClientBusinessObjects(newDataList);
+ List<BaseModel> newCboList = new ArrayList<>();
+ newDataList.stream().forEach(stringStringMap -> {
+ BaseModel baseModel=new BaseModel();
+ DefaultAttrAssimtUtil.copplyDefaultAttrAssimt(stringStringMap,baseModel,false,user);
+ baseModel.setData(stringStringMap);
+ newCboList.add(baseModel);
+ });
+ // 娣诲姞閿欒鍊�
+ String rowIndex = cbo.getAttributeValue(IMPORT_ROW_INDEX);
+ errorMap.put(rowIndex, "閲嶅鐨勮褰曠紪鍙蜂负:"+repeatData.stream().collect(Collectors.joining(",")));
+ if(!CollectionUtils.isEmpty(newCboList)) {
+ indexTODataMap.put(cbo.getAttributeValue(IMPORT_ROW_INDEX), newCboList);
+ }
+ }
+ return !repeatData.isEmpty();
+ }else{
+ return false;
}
- return !repeatData.isEmpty();
- }else{
- return false;
- }
- }).collect(Collectors.toList());
+ }).collect(Collectors.toList());
+ }).join();
if(!CollectionUtils.isEmpty(repeatDataMap)){
resultVO.setKeyAttrRepeatRowIndexList(repeatDataMap.stream().map(s->s.getAttributeValue(IMPORT_ROW_INDEX)).collect(Collectors.toSet()));
}
--
Gitblit v1.9.3