From d74e1672af99afd7e6a24327deb22b308dd5fc88 Mon Sep 17 00:00:00 2001
From: yuxc <653031404@qq.com>
Date: 星期一, 04 十二月 2023 08:38:44 +0800
Subject: [PATCH] Merge remote-tracking branch 'origin/master'

---
 Source/UBCS/ubcs-service/ubcs-code/src/main/java/com/vci/ubcs/code/service/impl/MdmIOServiceImpl.java |  209 ++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 202 insertions(+), 7 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 371139a..dfc6153 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
@@ -5,12 +5,14 @@
 import com.alibaba.nacos.common.utils.StringUtils;
 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import com.google.protobuf.ServiceException;
+import com.vci.ubcs.code.applyjtcodeservice.entity.DockingPreAttrMapping;
 import com.vci.ubcs.code.applyjtcodeservice.feign.IMdmInterJtClient;
+import com.vci.ubcs.code.applyjtcodeservice.vo.DockingPreAttrMappingVO;
 import com.vci.ubcs.code.bo.AttributeValue;
 import com.vci.ubcs.code.bo.CodeClassifyFullInfoBO;
 import com.vci.ubcs.code.bo.CodeTemplateAttrSqlBO;
-import com.vci.ubcs.code.dto.CodeExportAttrDTO;
-import com.vci.ubcs.code.dto.CodeOrderDTO;
+import com.vci.ubcs.code.constant.MdmEngineConstant;
+import com.vci.ubcs.code.dto.*;
 import com.vci.ubcs.code.entity.CodeAllCode;
 import com.vci.ubcs.code.enumpack.CodeDefaultLC;
 import com.vci.ubcs.code.enumpack.CodeLevelTypeEnum;
@@ -843,7 +845,7 @@
 				}
 				// 鍗曟瀵煎叆鏁伴噺闄愬埗
 				if(sheetDataSetList.get(i).getRowData().size() > IMPORT_DATA_LIMIT){
-					throw new ServiceException("涓轰簡淇濊瘉绯荤粺鐨勭ǔ瀹氭�э紝璇蜂竴娆′笉瑕佸鍏ヨ秴杩�"+IMPORT_DATA_LIMIT+"鏉$殑鏁版嵁");
+					throw new ServiceException(StringUtil.format("涓轰簡淇濊瘉绯荤粺鐨勭ǔ瀹氭�э紝璇蜂竴娆′笉瑕佸鍏ヨ秴杩噞}鏉$殑鏁版嵁",IMPORT_DATA_LIMIT));
 				}
 				//鍘嗗彶瀵煎叆鐨勬椂鍊欎笉澶勭悊缂栫爜
 				//----閫昏緫鍐呭----
@@ -1132,7 +1134,7 @@
 			if(StringUtils.isNotBlank(excelFileName)) {
 				codeImProtRusultVO.setFilePath(excelFileName);
 				codeImProtRusultVO.setFileOid("");
-				saveLogUtil.operateLog("鍘嗗彶鏁版嵁瀵煎叆",true, StringUtil.format("閿欒淇℃伅锛歿}",JSON.toJSONString(shetNameMap)) );
+				saveLogUtil.operateLog("鍘嗗彶鏁版嵁瀵煎叆",true, StringUtil.format("閿欒淇℃伅锛歿}",JSON.toJSONString(shetNameMap)));
 			}else{
 				saveLogUtil.operateLog("鍘嗗彶鏁版嵁瀵煎叆",false, StringUtil.format("瀵煎叆鍒板垎绫粄}涓紝瀵煎叆鎴愬姛鎬绘暟涓猴細{}", JSON.toJSONString(classifyFullInfo),importCount.get(0)));
 			}
@@ -1141,7 +1143,7 @@
 			}
 			return codeImProtRusultVO;
 		}catch (Exception e){
-			saveLogUtil.operateLog("鍘嗗彶鏁版嵁瀵煎叆",true,e.getMessage());
+			saveLogUtil.operateLog("鍘嗗彶鏁版嵁瀵煎叆",true,e.toString());
 			throw e;
 		}
 	}
@@ -1456,7 +1458,7 @@
 			}
 			saveLogUtil.operateLog("鎵归噺鐢宠缂栫爜",false, StringUtil.format("鎵归噺瀵煎叆鐢宠鎴愬姛鍏眥}鏉℃暟鎹紝鐢熸垚鐨勭爜鍊煎涓嬨�恵}銆�",codeList.size(),codeList));
 		}catch (Exception e){
-			saveLogUtil.operateLog("鎵归噺鐢宠缂栫爜",true,e.getMessage());
+			saveLogUtil.operateLog("鎵归噺鐢宠缂栫爜",true,e.toString());
 			throw e;
 		}
 		return uuid;
@@ -3824,7 +3826,7 @@
 	private void batchSwitchClassifyAttrOnOrder(Collection<CodeClassifyTemplateAttrVO> attrVOS,List<ClientBusinessObject> dataList,
 												CodeClassifyFullInfoBO classifyFullInfo,boolean isImPort) {
 		Map<String, CodeClassifyTemplateAttrVO> dateAttrVOMap = attrVOS.stream().filter(
-			s -> StringUtils.isNotBlank(s.getClassifyInvokeAttr()) && StringUtils.isNotBlank(s.getClassifyInvokeAttr())
+			s -> StringUtils.isNotBlank(s.getClassifyInvokeAttr())
 		).collect(Collectors.toMap(s -> s.getId().toLowerCase(Locale.ROOT), t -> t));
 		Map<String,CodeClassifyFullInfoBO> classifyFullInfoMap=new HashMap<>();
 		classifyFullInfoMap.put(classifyFullInfo.getCurrentClassifyVO().getOid(),classifyFullInfo);
@@ -3861,6 +3863,7 @@
 						} else {
 							Map<String, String> classifyDataMap = VciBaseUtil.objectToMapString(classifyVO);
 							String value = classifyDataMap.getOrDefault(attrVO.getClassifyInvokeAttr(), "");
+							log.error("================================褰撳墠鍒嗙被娉ㄥ叆鐨剉alue鍊间负锛�==========================",value);
 							cbo.setAttributeValue(attrId, value);
 						}
 					} catch (Throwable e) {
@@ -4605,4 +4608,196 @@
 		}
 	}
 
+	/***
+	 * @param codeClassifyOid
+	 * @return
+	 */
+	@Override
+	public String exportGroupCodeExcel(String codeClassifyOid) throws ServiceException {
+		VciBaseUtil.alertNotNull(codeClassifyOid,"涓婚搴撳垎绫荤殑涓婚敭");
+		CodeClassifyFullInfoBO classifyFullInfo = classifyService.getClassifyFullInfo(codeClassifyOid);
+		CodeClassifyVO codeClassifyVO= classifyFullInfo.getCurrentClassifyVO();
+		//鑾峰彇鏈�鏂扮殑妯℃澘
+		CodeClassifyTemplateVO templateVO = engineService.getUsedTemplateByClassifyOid(codeClassifyOid);
+		LinkedList<String> colName=new LinkedList<>();//鍒楀ご
+		LinkedList<String> fieldList=new LinkedList<>();//鍒楀瓧娈�
+
+		ExecGroupCodePortDataDTO execGroupCodePortDataDTO=new ExecGroupCodePortDataDTO();
+		createExportGroupCodeMapConfig(templateVO,execGroupCodePortDataDTO);//缁勭粐鏁版嵁
+		if(!CollectionUtils.isEmpty(execGroupCodePortDataDTO.getCodeAttrMapGroupAttrDTOS())){
+			throw new ServiceException("闆嗗洟灞炴�ф槧灏勬湭閰嶇疆");
+		}
+		fieldList=execGroupCodePortDataDTO.getFieldList();
+		List<Map<String,String>>dataList=new ArrayList<>();
+		getDatas(classifyFullInfo,templateVO,fieldList,dataList);
+		execGroupCodePortDataDTO.setDataList(dataList);//鏀炬暟鎹�
+		execGroupCodePortDataDTO.setSheetName(codeClassifyVO.getName()+"闆嗗洟鐮佸鍏ユā鏉�");
+		String tempFolder = LocalFileUtil.getDefaultTempFolder();
+		String excelName = tempFolder + File.separator +
+			classifyFullInfo.getCurrentClassifyVO().getId() + "_" + classifyFullInfo.getCurrentClassifyVO().getName() + "_闆嗗洟鐮佸鍑烘ā鏉�.xls";
+		try {
+			new File(excelName).createNewFile();
+		} catch (Throwable e) {
+			throw new VciBaseException(LangBaseUtil.getErrorMsg(e), new String[]{excelName}, e);
+		}
+		LinkedList<String> finalFieldList = fieldList;
+		Map<String, CodeClassifyTemplateAttrVO> attrVOMap = templateVO.getAttributes().stream().filter(s-> finalFieldList.contains(s.getId().toLowerCase(Locale.ROOT))).collect(Collectors.toMap(s -> s.getId().toLowerCase(Locale.ROOT), t -> t));
+		List<WriteExcelData> excelDataList = new ArrayList<>();
+		Workbook workbook = new HSSFWorkbook();
+		List<CodeAndGroupCodeAttrMappingDTO>  codeAndGroupCodeAttrMappingDTOList=	execGroupCodePortDataDTO.getCodeAttrMapGroupAttrDTOS();
+
+		Map<String, CodeAndGroupCodeAttrMappingDTO> jAttrVOMap = codeAndGroupCodeAttrMappingDTOList.stream().filter(s-> finalFieldList.contains(s.getTargetAttrKey().toLowerCase(Locale.ROOT))).collect(Collectors.toMap(s -> s.getTargetAttrKey().toLowerCase(Locale.ROOT), t -> t));
+
+		WriteExcelData codeExcelData = new WriteExcelData(0, 0, "浼佷笟缂栫爜");
+		WriteExcelData groupExcelData = new WriteExcelData(0, 1, "闆嗗洟鐮�");
+		excelDataList.add(codeExcelData);
+		excelDataList.add(groupExcelData);
+		for (int i = 0; i < fieldList.size(); i++) {
+			String attrId=fieldList.get(i);
+			if(attrId.equals(CODE_FIELD)||attrId.equals(CODE_GROUP_FIELD)){
+				continue;
+			}
+			if (attrVOMap.containsKey(attrId)) {
+				CodeClassifyTemplateAttrVO attrVO = attrVOMap.get(attrId);
+				//Object text = attrVO.getName();
+				CodeAndGroupCodeAttrMappingDTO codeAttrMappingDTO = jAttrVOMap.get(attrId);
+				Object text = codeAttrMappingDTO.getSourceAttrName();
+				text = exportKeyAndRequired(workbook, attrVO, text);
+				WriteExcelData excelData = new WriteExcelData(0, i, text);
+				if (text instanceof RichTextString) {
+					excelData.setFontColor(String.valueOf(HSSFColor.HSSFColorPredefined.RED.getIndex()));
+				}
+				excelDataList.add(excelData);
+			}
+		}
+		final Integer[] rowIndex = {0};
+		dataList.stream().forEach(data -> {
+			rowIndex[0]++;
+			String id=data.getOrDefault("id", "");
+			excelDataList.add(new WriteExcelData(rowIndex[0], 0, id));
+			String groupCode=data.getOrDefault("groupcode", "");
+			excelDataList.add(new WriteExcelData(rowIndex[0], 1, groupCode));
+			List<String> newFieldList = finalFieldList.stream().filter(e -> !e.equals("id") &&!e.equals("groupcode")).collect(Collectors.toList());
+
+			for (int i = 0; i < newFieldList.size(); i++) {
+				String attrId = newFieldList.get(i).toLowerCase(Locale.ROOT);
+				if(attrId.equals("id")){
+
+				}else if(attrId.equals("groupcode")){
+
+				}else{
+					if (attrVOMap.containsKey(attrId)) {
+						CodeClassifyTemplateAttrVO attrVO = attrVOMap.get(attrId);
+						if (StringUtils.isNotBlank(attrVO.getEnumId()) || StringUtils.isNotBlank(attrVO.getEnumString())) {
+							attrId = attrId + "Text";
+						}
+						if (StringUtils.isNotBlank(attrVO.getReferBtmId()) || StringUtils.isNotBlank(attrVO.getReferConfig())) {
+							attrId = attrId + "name";
+						}
+						if (VciQueryWrapperForDO.LC_STATUS_FIELD.equalsIgnoreCase(attrId)) {
+							attrId = VciQueryWrapperForDO.LC_STATUS_FIELD_TEXT.toLowerCase(Locale.ROOT);
+						}
+						excelDataList.add(new WriteExcelData(rowIndex[0], i+2, data.getOrDefault(attrId, "")));
+					}
+				}
+			}
+		});
+		WriteExcelOption excelOption = new WriteExcelOption();
+		excelOption.addSheetDataList(execGroupCodePortDataDTO.getSheetName(),excelDataList);
+
+		//澧炲姞妯℃澘鐨勪俊鎭鍏�
+		LinkedList<WriteExcelData> tempEDList = new LinkedList<>();
+		tempEDList.add(new WriteExcelData(0,0,"妯℃澘涓婚敭"));
+		tempEDList.add(new WriteExcelData(0,1,"妯℃澘浠e彿"));
+		tempEDList.add(new WriteExcelData(0,2,"妯℃澘鍚嶇О"));
+		tempEDList.add(new WriteExcelData(1,0,templateVO.getOid()));
+		tempEDList.add(new WriteExcelData(1,1,templateVO.getId()));
+		tempEDList.add(new WriteExcelData(1,2,templateVO.getName()));
+		excelOption.addSheetDataList("妯℃澘淇℃伅銆愯鍕垮垹闄ゆ垨绉诲姩銆�",tempEDList);
+		ExcelUtil.writeDataToFile(excelName, excelOption);
+		log.info("鏂囦欢璺緞"+excelName);
+		return excelName;
+	}
+
+	/***
+	 * 闆嗗洟瀵煎嚭妯℃澘灞炴�ф槧灏勪俊鎭幏鍙�
+	 * @param templateVO
+	 * @param execGroupCodePortDataDTO
+	 */
+	private void createExportGroupCodeMapConfig(CodeClassifyTemplateVO templateVO,ExecGroupCodePortDataDTO execGroupCodePortDataDTO){
+		String classOid=templateVO.getCodeclassifyoid();
+		String templateOid=templateVO.getOid();
+		R r=mdmInterJtClient.list_mapping(classOid);
+		if(r.isSuccess()){
+			List<DockingPreAttrMappingVO>dockingPreAttrMappingVOList= (List<DockingPreAttrMappingVO>) r.getData();
+			List<CodeAndGroupCodeAttrMappingDTO> codeAttrMapGroupAttrDTOS=new ArrayList<>();
+			LinkedList<String> fieldList=new LinkedList<>();
+			LinkedList<String> colNameList=new LinkedList<>();
+			dockingPreAttrMappingVOList.stream().forEach(dockingPreAttrMappingVO -> {
+				CodeAndGroupCodeAttrMappingDTO codeAndGroupCodeAttrMappingDTO=new CodeAndGroupCodeAttrMappingDTO();
+				if(StringUtils.isNotBlank(dockingPreAttrMappingVO.getTargetAttrId())){
+					codeAndGroupCodeAttrMappingDTO.setDefaultValue(dockingPreAttrMappingVO.getDefaultValue());
+					codeAndGroupCodeAttrMappingDTO.setMetaListId(dockingPreAttrMappingVO.getMetaListId());
+					codeAndGroupCodeAttrMappingDTO.setSourceAttrKey(dockingPreAttrMappingVO.getSourceAttrKey());
+					codeAndGroupCodeAttrMappingDTO.setSourceAttrName(dockingPreAttrMappingVO.getSourceAttrName());
+					codeAndGroupCodeAttrMappingDTO.setTargetAttrId(dockingPreAttrMappingVO.getTargetAttrId());
+					codeAndGroupCodeAttrMappingDTO.setTargetAttrKey(dockingPreAttrMappingVO.getTargetAttrKey());
+					codeAndGroupCodeAttrMappingDTO.setTargetAttrName(dockingPreAttrMappingVO.getTargetAttrName());
+					fieldList.add(dockingPreAttrMappingVO.getTargetAttrKey());
+					colNameList.add(dockingPreAttrMappingVO.getSourceAttrName());
+				}
+				codeAttrMapGroupAttrDTOS.add(codeAndGroupCodeAttrMappingDTO);
+			});
+			execGroupCodePortDataDTO.setCodeAttrMapGroupAttrDTOS(codeAttrMapGroupAttrDTOS);
+			execGroupCodePortDataDTO.setFieldList(fieldList);
+			execGroupCodePortDataDTO.setColName(colNameList);
+		}
+	}
+
+	/***
+	 * 鏌ヨ鏈湁闆嗗洟鐮佺殑鏁版嵁
+	 * @param classifyFullInfo
+	 * @param templateVO
+	 * @param selectFieldList
+	 * @param dataList
+	 */
+	private void getDatas(CodeClassifyFullInfoBO classifyFullInfo,CodeClassifyTemplateVO templateVO,LinkedList<String> selectFieldList,List<Map<String,String>>dataList){
+		//鍏堟煡璇㈡暟鎹�
+		String btmTypeId = classifyFullInfo.getTopClassifyVO().getBtmTypeId();
+		String codeClassifyOid=classifyFullInfo.getCurrentClassifyVO().getOid();
+		Map<String, String> conditionMap = new HashMap<>();
+		if(conditionMap == null){
+			conditionMap = new HashMap<>();
+		}
+		if(conditionMap.containsKey(VciQueryWrapperForDO.OID_FIELD)){
+			conditionMap.put(VciQueryWrapperForDO.OID_FIELD,QueryOptionConstant.IN + "(" + VciBaseUtil.toInSql(conditionMap.get(VciQueryWrapperForDO.OID_FIELD)) + ")");
+		}
+		conditionMap.put("codeclsfpath","*" + codeClassifyOid + "*");
+		conditionMap.put("groupcode_null", "null");
+		conditionMap.put("lastr", "1");
+		conditionMap.put("lastv", "1");
+
+		R<List<BtmTypeVO>> listR = btmTypeClient.selectByIdCollection(Arrays.asList(btmTypeId));
+		String tableName = "";
+		if(listR.isSuccess() && !listR.getData().isEmpty()){
+			tableName = Func.isNotBlank(listR.getData().get(0).getTableName()) ? listR.getData().get(0).getTableName():VciBaseUtil.getTableName(btmTypeId);
+		}else{
+			tableName = VciBaseUtil.getTableName(btmTypeId);
+		}
+		PageHelper pageHelper = new PageHelper();
+		pageHelper.setLimit(1000000);
+		pageHelper.setPage(1);
+		pageHelper.addDefaultDesc("createTime");
+		DataGrid<Map<String, String>> dataGrid = engineService.queryGrid(btmTypeId, templateVO, conditionMap, pageHelper);
+		//杞崲鏁版嵁
+		if(!CollectionUtils.isEmpty(dataGrid.getData())){
+			dataList.addAll(dataGrid.getData());
+		}
+		//灏佽鏌ヨ鍑烘潵鐨勬暟鎹�
+		engineService.wrapperData(dataList, templateVO, selectFieldList,false);
+		//modify by weidy@2022-09-27
+		//鍥犱负鍦ㄥ垪琛ㄥ拰琛ㄥ崟鐨勬樉绀虹殑鏃跺�欙紝鎴戜滑鐨勫紑鍏崇被鍨嬮〉闈細澶勭悊锛屼絾鏄湪瀵煎嚭鐨勬椂鍊欙紝鎴戜滑闇�瑕佸皢true鍜宖alse閮芥浛鎹㈡垚涓枃
+		engineService.wrapperBoolean(dataList,templateVO);
+		log.info("瀵煎嚭妯℃澘鐨勬暟鎹潯鐩暟:"+dataList.size());
+	}
 }

--
Gitblit v1.9.3