From 7d9733a9fe0e21efe346787838aa5182633e30d2 Mon Sep 17 00:00:00 2001
From: ludc
Date: 星期日, 08 十月 2023 22:33:10 +0800
Subject: [PATCH] 注意更新blade-core-tool.jar

---
 Source/UBCS/ubcs-service/ubcs-code/src/main/java/com/vci/ubcs/code/service/impl/MdmProductCodeServiceImpl.java |   97 ++++++++++++++++++++++++++++++------------------
 1 files changed, 60 insertions(+), 37 deletions(-)

diff --git a/Source/UBCS/ubcs-service/ubcs-code/src/main/java/com/vci/ubcs/code/service/impl/MdmProductCodeServiceImpl.java b/Source/UBCS/ubcs-service/ubcs-code/src/main/java/com/vci/ubcs/code/service/impl/MdmProductCodeServiceImpl.java
index f199450..98bbea7 100644
--- a/Source/UBCS/ubcs-service/ubcs-code/src/main/java/com/vci/ubcs/code/service/impl/MdmProductCodeServiceImpl.java
+++ b/Source/UBCS/ubcs-service/ubcs-code/src/main/java/com/vci/ubcs/code/service/impl/MdmProductCodeServiceImpl.java
@@ -2,18 +2,18 @@
 
 import com.alibaba.nacos.common.utils.StringUtils;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
-import com.baomidou.mybatisplus.core.toolkit.BeanUtils;
 import com.vci.ubcs.code.bo.CodeClassifyFullInfoBO;
 import com.vci.ubcs.code.dto.CodeOrderSecDTO;
 import com.vci.ubcs.code.entity.CodeAllCode;
+import com.vci.ubcs.code.entity.CodeClassifyValue;
 import com.vci.ubcs.code.entity.CodeSerialValue;
 import com.vci.ubcs.code.enumpack.CodeCutTypeEnum;
 import com.vci.ubcs.code.enumpack.CodeGetValueTypeEnum;
 import com.vci.ubcs.code.enumpack.CodeLevelTypeEnum;
 import com.vci.ubcs.code.enumpack.CodeSecTypeEnum;
 import com.vci.ubcs.code.lifecycle.CodeAllCodeLC;
+import com.vci.ubcs.code.mapper.CodeClassifyValueMapper;
 import com.vci.ubcs.code.mapper.CodeSerialValueMapper;
-import com.vci.ubcs.code.service.ICodeWupinService;
 import com.vci.ubcs.code.service.MdmEngineService;
 import com.vci.ubcs.code.service.MdmProductCodeService;
 import com.vci.ubcs.code.vo.pagemodel.CodeBasicSecVO;
@@ -23,6 +23,7 @@
 import com.vci.ubcs.starter.exception.VciBaseException;
 import com.vci.ubcs.starter.revision.model.BaseModel;
 import com.vci.ubcs.starter.util.DefaultAttrAssimtUtil;
+import com.vci.ubcs.starter.util.MdmBtmTypeConstant;
 import com.vci.ubcs.starter.web.constant.QueryOptionConstant;
 import com.vci.ubcs.starter.web.constant.RegExpConstant;
 import com.vci.ubcs.starter.web.enumpck.OsCodeFillTypeEnum;
@@ -31,6 +32,7 @@
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.context.annotation.Lazy;
 import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
 import org.springframework.util.CollectionUtils;
 
 import javax.annotation.Resource;
@@ -49,16 +51,17 @@
 	private CodeSerialValueMapper serialValueMapper;
 
 	/**
-	 * 鎵�鏈夌殑缂栫爜鐨勫唴瀹�
+	 * 娴佹按鍙风殑鐩稿叧鐨勪俊鎭�
 	 */
 	@Resource
-	private CodeAllCodeServiceImpl codeAllCodeService;
+	private CodeClassifyValueMapper codeClassifyValueMapper;
 
 	/**
 	 * 鎵�鏈夌殑缂栫爜鐨勫唴瀹�
 	 */
 	@Resource
-	private ICodeWupinService iCodeWupinService;
+	private CodeAllCodeServiceImpl codeAllCodeService;
+
 	/**
 	 * 鎵�鏈夌殑缂栫爜鐨勫唴瀹�
 	 */
@@ -73,11 +76,9 @@
 	private FormulaServiceImpl formulaService;
 
 	@Override
+	@Transactional(rollbackFor = VciBaseException.class)
 	public List<String> productCodeAndSaveData(CodeClassifyFullInfoBO classifyFullInfoBO, CodeClassifyTemplateVO templateVO, CodeRuleVO ruleVO, List<CodeOrderSecDTO> secDTOList, List<BaseModel> dataCBOList) throws Exception {
-//		BatchCBO batchCBO = new BatchCBO();
-//		WebUtil.setPersistence(false);
 		dataCBOList = dataCBOList.stream().sorted(((o1, o2) -> o1.getCreateTime().compareTo(o2.getCreateTime()))).collect(Collectors.toList());
-//		batchCBO.getCreateCbos().addAll(dataCBOList);
 		List<String> codeList = new ArrayList<>();
 
 		/*****
@@ -99,6 +100,9 @@
 				String code = cbo.getId();
 				List<String> serialUnitList = new ArrayList<>();
 				String[] secLengths = cbo.getData().get(CODE_SEC_LENGTH_FIELD).split("#");
+				cbo.getData().remove(CODE_SEC_LENGTH_FIELD);//灏嗘key闄ゅ幓
+				cbo.getData().remove(IMPORT_ROW_INDEX);//灏嗘key闄ゅ幓
+				cbo.getData().remove("codeclassifyid");//灏嗘key闄ゅ幓
 				List<CodeBasicSecVO> secVOList = ruleVO.getSecVOList().stream().sorted(((o1, o2) -> o1.getOrderNum().compareTo(o2.getOrderNum()))).collect(Collectors.toList());
 				Map<String/**鐮佹鐨勪富閿�**/,String/**鐮佹鐨勫��**/> serialValueMap = new HashMap<>();
 				Map<String, CodeBasicSecVO> secVOMap = secVOList.stream().collect(Collectors.toMap(s -> s.getOid(), t -> t));
@@ -147,6 +151,7 @@
 					});
 				}
 				CodeAllCode allCodeDO = new CodeAllCode();
+				DefaultAttrAssimtUtil.addDefaultAttrAssimt(allCodeDO, MdmBtmTypeConstant.CODE_ALL_CODE);
 				allCodeDO.setCodeClassifyOid(classifyFullInfoBO.getCurrentClassifyVO().getOid());
 				allCodeDO.setCodeRuleOid(ruleVO.getOid());
 				allCodeDO.setId(cbo.getId());
@@ -163,27 +168,24 @@
 			List<CodeSerialValue> editSerialValueList = new ArrayList<>();
 			maxSerialMap.forEach((serialUnit,secOidMaxMap)->{
 				secOidMaxMap.forEach((secOid,maxSerial)->{
-//					Map<String, String> conditionMap = new HashMap<>();
-//					conditionMap.put("codeRuleOid", ruleVO.getOid());
-//					conditionMap.put("serialUnit", serialUnit);
-//					//杩欎釜瀛楁鏄负浜嗚В鍐冲涓祦姘寸殑闂
-//					conditionMap.put("codeSecOid", secOid);
 					QueryWrapper<CodeSerialValue> queryWrapper = new QueryWrapper<>();
 					queryWrapper.eq("codeRuleOid", ruleVO.getOid());
 					queryWrapper.eq("serialUnit", serialUnit);
+					//杩欎釜瀛楁鏄负浜嗚В鍐冲涓祦姘寸殑闂
 					queryWrapper.eq("codeSecOid", secOid);
 
 					List<CodeSerialValue> serialValueDOS = serialValueMapper.selectList(queryWrapper);
-//					.selectByCondition(conditionMap, new PageHelper(-1));
 					if (!CollectionUtils.isEmpty(serialValueDOS)) {
 						CodeSerialValue serialValueDO = serialValueDOS.get(0);
 						if(VciBaseUtil.getDouble(serialValueDO.getMaxSerial())<maxSerial){
 							serialValueDO.setMaxSerial(String.valueOf(maxSerial));
+							DefaultAttrAssimtUtil.updateDefaultAttrAssimt(serialValueDO);
 							editSerialValueList.add(serialValueDO);
 						}
 					}else{
 						//娌℃湁
 						CodeSerialValue serialValueDO = new CodeSerialValue();
+						DefaultAttrAssimtUtil.addDefaultAttrAssimt(serialValueDO, MdmBtmTypeConstant.CODE_SERIAL_VALUE);
 						serialValueDO.setCodeRuleOid(ruleVO.getOid());
 						serialValueDO.setSerialUnit(serialUnit);
 						serialValueDO.setCodeSecOid(secOid);
@@ -193,31 +195,23 @@
 				});
 			});
 			if(!CollectionUtils.isEmpty(addSerialValueList)){
-//				batchCBO.copyFromOther(serialValueMapper.batchInsert(addSerialValueList));
 				for (CodeSerialValue codeSerialValue : addSerialValueList) {
 					serialValueMapper.insert(codeSerialValue);
 				}
-//				serialValueMapper.ba
-
 			}
 			if(!CollectionUtils.isEmpty(editSerialValueList)){
 				for (CodeSerialValue codeSerialValue : editSerialValueList) {
 					serialValueMapper.updateById(codeSerialValue);
 				}
-
-//				batchCBO.copyFromOther(serialValueMapper.batchUpdate(editSerialValueList));
 			}
 			//澶勭悊allCode
 			if(!CollectionUtils.isEmpty(allCodeDOList)){
-				Map<String, List<CodeAllCode>> ruleGroup = allCodeDOList.stream().collect(Collectors.groupingBy(s -> s.getCodeRuleOid()));
+				Map<String,List<CodeAllCode>> ruleGroup = allCodeDOList.stream().collect(Collectors.groupingBy(s -> s.getCodeRuleOid()));
 				Map<String, CodeAllCode> codeDOMap = allCodeDOList.stream().collect(Collectors.toMap(s -> s.getCodeRuleOid() + "${SEP}" + s.getId(), t -> t));
 				List<CodeAllCode> addCodeDOs = new ArrayList<>();
 				List<CodeAllCode> editCodeDOs = new ArrayList<>();
 				ruleGroup.forEach((ruleOid,allCodeDOS)->{
 					VciBaseUtil.switchCollectionForOracleIn(allCodeDOS).stream().forEach(codeDOs->{
-//						Map<String,String> conditionMap = new HashMap<>();
-//						conditionMap.put("coderuleoid",ruleOid);
-//						conditionMap.put("id",QueryOptionConstant.IN + "(" + VciBaseUtil.toInSql(codeDOs.stream().map(s->s.getId()).collect(Collectors.toList()).toArray(new String[0])) + ")");
 						QueryWrapper<CodeAllCode> allCodeWrapper = new QueryWrapper<>();
 						allCodeWrapper.eq("coderuleoid",ruleOid);
 						allCodeWrapper.in("id", QueryOptionConstant.IN + "(" +
@@ -248,26 +242,31 @@
 					addCodeDOs = allCodeDOList;
 				}
 				if(!CollectionUtils.isEmpty(editCodeDOs)){
-//					batchCBO.copyFromOther(allCodeMapper.batchUpdate(editCodeDOs));
 					codeAllCodeService.updateBatchById(editCodeDOs);
 				}
 				if(!CollectionUtils.isEmpty(addCodeDOs)){
-//					batchCBO.copyFromOther(allCodeMapper.batchInsert(addCodeDOs));
 					Map<String, String> statusMap = addCodeDOs.stream().collect(Collectors.toMap(s -> s.getOid(), s -> s.getLcStatus()));
 					addCodeDOs.stream().filter(s -> StringUtils.equalsIgnoreCase("codeallcode",s.getBtmname())).forEach(s -> {
 						s.setLcStatus(statusMap.get(s.getOid()));
 					});
+					//閫氳繃ID鏉ヨ繘琛屽幓閲�
+					List<CodeAllCode> distinctCodeAllCOdes = addCodeDOs.stream().collect(Collectors
+						.collectingAndThen(
+							Collectors.toCollection(() -> new TreeSet<>(Comparator.comparing(CodeAllCode::getId))),
+							ArrayList::new));
+					if( distinctCodeAllCOdes.size() != addCodeDOs.size() ){
+						throw new VciBaseException("缂栫爜鏁版嵁閲嶅锛屾棤娉曚繚瀛橈紝璇锋敞鎰忥紒");
+					}
 					codeAllCodeService.saveBatch(addCodeDOs);
 				}
+				mdmEngineService.insertBatchByType(dataCBOList.get(0).getBtmname(),dataCBOList);
 			}
-//			WebUtil.setPersistence(true);
-//			boService.persistenceBatch(batchCBO);
 			return codeList;
 		}else {
 			List<CodeBasicSecVO> secVOList = ruleVO.getSecVOList().stream().sorted(((o1, o2) -> o1.getOrderNum().compareTo(o2.getOrderNum()))).collect(Collectors.toList());
 			List<String> serialUnitList = new LinkedList<>();
 			List<String> secValueList = new ArrayList<>();
-			Map<String, String> secValueMap = secDTOList.stream().collect(Collectors.toMap(s -> s.getSecOid(), s -> s.getSecValue()));
+			Map<String, String> secValueMap = secDTOList.stream().collect(Collectors.toMap(s -> s.getSecOid(), s -> s.getSecValue()==null?"":s.getSecValue()));
 			List<CodeBasicSecVO> serialSecVOList = new ArrayList<>();
 			List<CodeBasicSecVO> attrSecVOList = new ArrayList<>();
 			for (int i = 0; i < secVOList.size(); i++) {
@@ -283,6 +282,9 @@
 
 			for (int i = 0; i < dataCBOList.size(); i++) {
 				BaseModel cbo = dataCBOList.get(i);
+				cbo.getData().remove(CODE_SEC_LENGTH_FIELD);//灏嗘key闄ゅ幓
+				cbo.getData().remove(IMPORT_ROW_INDEX);//灏嗘key闄ゅ幓
+				cbo.getData().remove("codeclassifyid");//灏嗘key闄ゅ幓
 				List<String> thisSecValueList = new LinkedList<>();
 				for (int j = 0; j < secValueList.size(); j++) {
 					thisSecValueList.add(secValueList.get(j));
@@ -316,16 +318,25 @@
 			}
 			saveSerialValue( ruleVO, lastMaxSerialValueMap, maxSerialValueMap);
 
+			allCodeDOList.stream().forEach(
+				allCode -> {DefaultAttrAssimtUtil.addDefaultAttrAssimt(allCode,"codeallcode");allCode.setLctid("codeAllCodeLC");}
+			);
+
+
 			Map<String, String> statusMap = allCodeDOList.stream().collect(Collectors.toMap(s -> s.getOid(), s -> s.getLcStatus()));
 			allCodeDOList.stream().filter(s -> StringUtils.equalsIgnoreCase("codeallcode",s.getBtmname())).forEach(s -> {
 				s.setLcStatus(statusMap.get(s.getOid()));
 			});
 
 
-			allCodeDOList.stream().forEach(
-				allCode -> {DefaultAttrAssimtUtil.addDefaultAttrAssimt(allCode,"codeallcode");allCode.setLctid("codeAllCodeLC");}
-			);
-
+			//閫氳繃ID鏉ヨ繘琛屽幓閲�
+			List<CodeAllCode> distinctCodeAllCOdes = allCodeDOList.stream().collect(Collectors
+				.collectingAndThen(
+					Collectors.toCollection(() -> new TreeSet<>(Comparator.comparing(CodeAllCode::getId))),
+					ArrayList::new));
+			if( distinctCodeAllCOdes.size() != allCodeDOList.size() ){
+				throw new VciBaseException("缂栫爜鏁版嵁閲嶅锛屾棤娉曚繚瀛橈紝璇锋敞鎰忥紒");
+			}
 			codeAllCodeService.saveBatch(allCodeDOList);
 //			iCodeWupinService.saveBatch(dataCBOList);
 			mdmEngineService.insertBatchByType(dataCBOList.get(0).getBtmname(),dataCBOList);
@@ -493,6 +504,10 @@
 				break;
 			case CODE_CLASSIFY_SEC:
 				//鍒嗙被鐮佹鐨勶紝涔熸槸浠庡墠绔�夋嫨浜嗙爜鍊煎嵆鍙紝涓嶈鐮佸�肩殑闀垮害鏄灏�
+				CodeClassifyValue codeClassifyValueDO= codeClassifyValueMapper.selectById(secValue);
+				if(codeClassifyValueDO!=null) {
+					secValue = codeClassifyValueDO.getId();
+				}
 				break;
 			case CODE_LEVEL_SEC:
 				//灞傜骇鐮佹锛岄渶瑕佷粠鍒嗙被涓婅幏鍙栫浉搴旂殑淇℃伅
@@ -503,7 +518,7 @@
 						secValue = classifyFullInfoBO.getCurrentClassifyVO().getId();
 					} else {
 						//鎴戜滑闇�瑕佷粠椤跺眰寮�濮嬫壘鍒板綋鍓嶅垎绫讳负姝�
-						secValue = classifyFullInfoBO.getParentClassifyVOs().stream().sorted(((o1, o2) -> o1.getDataLevel().compareTo(o2.getDataLevel()))).map(CodeClassifyVO::getId).collect(Collectors.joining()) + classifyFullInfoBO.getCurrentClassifyVO().getId();
+						secValue = classifyFullInfoBO.getParentClassifyVOs().stream().sorted(((o1, o2) -> -o1.getDataLevel().compareTo(o2.getDataLevel()))).map(CodeClassifyVO::getId).collect(Collectors.joining()) + classifyFullInfoBO.getCurrentClassifyVO().getId();
 					}
 				} else {
 					//鎸囧畾灞傦紝鎴戜滑闇�瑕侀�氳繃涓婄骇鐨勬潵鑾峰彇
@@ -512,7 +527,7 @@
 						secValue = classifyFullInfoBO.getCurrentClassifyVO().getId();
 					} else {
 						//杩欎釜鎴戜滑闇�瑕佺湅鐪�,灞傜骇鏄笉鏄ぇ浜庝簡鏈�澶у眰绾х殑鏁�
-						List<CodeClassifyVO> parentClassifyVOList = classifyFullInfoBO.getParentClassifyVOs().stream().sorted(((o1, o2) -> o1.getDataLevel().compareTo(o2.getDataLevel()))).collect(Collectors.toList());
+						List<CodeClassifyVO> parentClassifyVOList = classifyFullInfoBO.getParentClassifyVOs().stream().sorted(((o1, o2) -> -o1.getDataLevel().compareTo(o2.getDataLevel()))).collect(Collectors.toList());
 						if (secVO.getCodeLevelValue() > (parentClassifyVOList.size() + 1)) {
 							//鎸囧畾鐨勫眰绾ф瘮褰撳墠鐨勫眰绾ц繕澶т簡锛屾墍浠ュ彧鑳借幏鍙栧綋鍓嶅眰绾т簡
 							if (CodeGetValueTypeEnum.CURRENT.getValue().equalsIgnoreCase(secVO.getCodeGetValueType())) {
@@ -529,7 +544,7 @@
 								}
 							} else {
 								//灏忎簬绛変簬鐨勫叏閮ㄦ嬁鍑烘潵
-								secValue = parentClassifyVOList.stream().filter(s -> s.getDataLevel().intValue() <= secVO.getCodeLevelValue().intValue()).sorted(((o1, o2) -> o1.getDataLevel().compareTo(o2.getDataLevel()))).map(CodeClassifyVO::getId).collect(Collectors.joining());
+								secValue = parentClassifyVOList.stream().filter(s -> s.getDataLevel().intValue() <= secVO.getCodeLevelValue().intValue()).sorted(((o1, o2) -> -o1.getDataLevel().compareTo(o2.getDataLevel()))).map(CodeClassifyVO::getId).collect(Collectors.joining());
 							}
 						}
 					}
@@ -614,6 +629,7 @@
                                 BaseModel cbo, CodeClassifyTemplateVO templateVO,
                                 List<CodeAllCode> allCodeDOList, String serialUnitString, String serialValueString){
 		CodeAllCode allCodeDO = new CodeAllCode();
+		DefaultAttrAssimtUtil.addDefaultAttrAssimt(allCodeDO, MdmBtmTypeConstant.CODE_ALL_CODE);
 		allCodeDO.setCodeClassifyOid(classifyFullInfoBO.getCurrentClassifyVO().getOid());
 		allCodeDO.setCodeRuleOid(ruleVO.getOid());
 		allCodeDO.setId(cbo.getId());
@@ -648,9 +664,11 @@
 					//璇存槑鏈�
 					serialValueDO = maxSerialValueMap.get(secOid).get(unit);
 					serialValueDO.setMaxSerial(maxSerial.toString());
+					DefaultAttrAssimtUtil.updateDefaultAttrAssimt(serialValueDO);
 					editSerialValueDOList.add(serialValueDO);
 				}else{
 					serialValueDO = new CodeSerialValue();
+					DefaultAttrAssimtUtil.addDefaultAttrAssimt(serialValueDO, MdmBtmTypeConstant.CODE_SERIAL_VALUE);
 					serialValueDO.setCodeRuleOid(ruleVO.getOid());
 					serialValueDO.setSerialUnit(unit);
 					serialValueDO.setCodeSecOid(secOid);
@@ -773,8 +791,13 @@
 	 * @param rule 瑙勫垯鐨勫唴瀹�
 	 * @return 杞崲鍚庣殑
 	 */
-	private String getValueByFormulaForCBO(BaseModel cbo,String rule){
-		Map<String, Object> dataMap = BeanUtils.beanToMap(cbo);
+	private String getValueByFormulaForCBO(BaseModel cbo,String rule)  {
+		Map<String, Object> dataMap = null;
+		try{
+			dataMap = VciBaseUtil.convertBean2Map(cbo,null);
+		}catch(Exception e){
+			throw new VciBaseException("mapToBeanError:"+e);
+		}
 		Map<String, String> map = new HashMap<String, String>();
 		for (String i : dataMap.keySet()) {
 			map.put(i, String.valueOf(dataMap.get(i)));

--
Gitblit v1.9.3