From a472fa1f44b9976ce7e2b502814b130ec72e0f29 Mon Sep 17 00:00:00 2001
From: yuxc <653031404@qq.com>
Date: 星期三, 19 七月 2023 11:31:11 +0800
Subject: [PATCH] 1、主要解决在批量插入的时候通过业务类型去获取字段信息,对比字段没有的则不进行插入。

---
 Source/UBCS/ubcs-service/ubcs-code/src/main/java/com/vci/ubcs/code/service/impl/MdmEngineServiceImpl.java      |   25 ++++++++++++++++++++-----
 Source/UBCS/ubcs-service-api/ubcs-util-api/src/main/java/com/vci/ubcs/starter/web/util/VciBaseUtil.java        |   13 +++++++++++--
 Source/UBCS/ubcs-service/ubcs-code/src/main/java/com/vci/ubcs/code/service/impl/MdmProductCodeServiceImpl.java |    2 +-
 3 files changed, 32 insertions(+), 8 deletions(-)

diff --git a/Source/UBCS/ubcs-service-api/ubcs-util-api/src/main/java/com/vci/ubcs/starter/web/util/VciBaseUtil.java b/Source/UBCS/ubcs-service-api/ubcs-util-api/src/main/java/com/vci/ubcs/starter/web/util/VciBaseUtil.java
index 4a08af9..7bf46f2 100644
--- a/Source/UBCS/ubcs-service-api/ubcs-util-api/src/main/java/com/vci/ubcs/starter/web/util/VciBaseUtil.java
+++ b/Source/UBCS/ubcs-service-api/ubcs-util-api/src/main/java/com/vci/ubcs/starter/web/util/VciBaseUtil.java
@@ -1294,7 +1294,7 @@
 	 * @return Map瀵硅薄
 	 * @version 2016骞�3鏈�20鏃� 11:03:01
 	 */
-	public static Map convertBean2Map(Object bean) throws Exception {
+	public static Map convertBean2Map(Object bean,Set<String> existFild) throws Exception {
 		Class type = bean.getClass();
 		Map returnMap = new HashMap();
 		BeanInfo beanInfo = Introspector.getBeanInfo(type);
@@ -1332,7 +1332,16 @@
 
 				if (result != null) {
 					if ("data".equals(propertyName)){
-						returnMap.putAll((Map) result);
+						if(existFild == null){
+							returnMap.putAll((Map) result);
+						}else{
+							Map resulMap = (Map) result;
+							for (Object o : resulMap.keySet()) {
+								if(existFild.contains(o)){
+									returnMap.put(o,resulMap.get(o));
+								}
+							}
+						}
 					}else {
 						returnMap.put(fieldMap.containsKey(propertyName)?fieldMap.get(propertyName):propertyName, result);
 					}
diff --git a/Source/UBCS/ubcs-service/ubcs-code/src/main/java/com/vci/ubcs/code/service/impl/MdmEngineServiceImpl.java b/Source/UBCS/ubcs-service/ubcs-code/src/main/java/com/vci/ubcs/code/service/impl/MdmEngineServiceImpl.java
index ecb1dc6..eb7a13d 100644
--- a/Source/UBCS/ubcs-service/ubcs-code/src/main/java/com/vci/ubcs/code/service/impl/MdmEngineServiceImpl.java
+++ b/Source/UBCS/ubcs-service/ubcs-code/src/main/java/com/vci/ubcs/code/service/impl/MdmEngineServiceImpl.java
@@ -400,7 +400,6 @@
     public String addSaveCode(CodeOrderDTO orderDTO) throws Exception {
         VciBaseUtil.alertNotNull(orderDTO, "缂栫爜鐢宠鐩稿叧鐨勫睘鎬у拰鐮佹鐨勫唴瀹归兘涓虹┖", orderDTO.getCodeClassifyOid(), "涓婚搴撳垎绫荤殑涓婚敭",
                 orderDTO.getTemplateOid(), "妯℃澘鐨勪富閿�", orderDTO.getCodeRuleOid(), "缂栫爜瑙勫垯鐨勪富閿�");
-		VciSystemVarConstants.getSystemVarValueMap();
         CodeClassifyFullInfoBO classifyFullInfo = classifyService.getClassifyFullInfo(orderDTO.getCodeClassifyOid());
         CodeClassifyTemplateVO templateVO = templateService.getObjectHasAttrByOid(orderDTO.getTemplateOid());
         CodeRuleVO ruleVO = ruleService.getObjectHasSecByOid(orderDTO.getCodeRuleOid());
@@ -918,7 +917,7 @@
 
 //						baseModels.stream().forEach(model-> {
                         try {
-                            map = VciBaseUtil.convertBean2Map(cbo);
+                            map = VciBaseUtil.convertBean2Map(cbo,null);
                         } catch (Exception e) {
                             throw new VciBaseException("绫诲瀷杞崲閿欒锛�" + e.getMessage());
                         }
@@ -3254,11 +3253,19 @@
         if (!listR.isSuccess() || listR.getData().size() == 0) {
             throw new VciBaseException("浼犲叆涓氬姟绫诲瀷鏈煡璇㈠埌鐩稿簲琛ㄥ崟锛岃妫�鏌ワ紒");
         }
-        //灏哹ean杞负map,mybatis缁熶竴澶勭悊
+		//鑾峰彇褰撳墠涓氬姟绫诲瀷鎵�鏈夊瓧娈电敤鏉ュ仛瀵规瘮
+		R<BtmTypeVO> allAttributeByBtmId = btmTypeClient.getAllAttributeByBtmId(btmType);
+		if (!allAttributeByBtmId.isSuccess() || allAttributeByBtmId.getData().getAttributes().size() == 0) {
+			throw new VciBaseException("浼犲叆涓氬姟绫诲瀷鏈煡璇㈠埌鐩稿簲瀛楁淇℃伅锛岃妫�鏌ワ紒");
+		}
+		Set<String> existFild = allAttributeByBtmId.getData().getAttributes().stream().map(btmTypeAttributeVO -> {
+			return btmTypeAttributeVO.getId();
+		}).collect(Collectors.toSet());
+		//灏哹ean杞负map,mybatis缁熶竴澶勭悊
         List<Map<String, String>> maps = new ArrayList<>();
         baseModels.stream().forEach(model -> {
             try {
-                maps.add(VciBaseUtil.convertBean2Map(model));
+                maps.add(VciBaseUtil.convertBean2Map(model,existFild));
             } catch (Exception e) {
                 throw new VciBaseException("绫诲瀷杞崲閿欒锛�" + e.toString());
             }
@@ -3409,12 +3416,20 @@
         if (!listR.isSuccess() || listR.getData().size() == 0) {
             throw new VciBaseException("浼犲叆涓氬姟绫诲瀷鏈煡璇㈠埌鐩稿簲琛ㄥ崟锛岃妫�鏌ワ紒");
         }
+		//鑾峰彇褰撳墠涓氬姟绫诲瀷鎵�鏈夊瓧娈电敤鏉ュ仛瀵规瘮
+		R<BtmTypeVO> allAttributeByBtmId = btmTypeClient.getAllAttributeByBtmId(btmType);
+		if (!allAttributeByBtmId.isSuccess() || allAttributeByBtmId.getData().getAttributes().size() == 0) {
+			throw new VciBaseException("浼犲叆涓氬姟绫诲瀷鏈煡璇㈠埌鐩稿簲瀛楁淇℃伅锛岃妫�鏌ワ紒");
+		}
+		Set<String> existFild = allAttributeByBtmId.getData().getAttributes().stream().map(btmTypeAttributeVO -> {
+			return btmTypeAttributeVO.getId();
+		}).collect(Collectors.toSet());
         //灏哹ean杞负map,mybatis缁熶竴澶勭悊
         List<Map<String, String>> maps = new ArrayList<>();
 
         baseModels.stream().forEach(model -> {
             try {
-                maps.add(VciBaseUtil.convertBean2Map(model));
+                maps.add(VciBaseUtil.convertBean2Map(model,existFild));
             } catch (Exception e) {
                 throw new VciBaseException("绫诲瀷杞崲閿欒锛�" + e.getMessage());
             }
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 5b86905..58a305b 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
@@ -789,7 +789,7 @@
 	private String getValueByFormulaForCBO(BaseModel cbo,String rule)  {
 		Map<String, Object> dataMap = null;
 		try{
-			dataMap = VciBaseUtil.convertBean2Map(cbo);
+			dataMap = VciBaseUtil.convertBean2Map(cbo,null);
 		}catch(Exception e){
 			throw new VciBaseException("mapToBeanError:"+e);
 		}

--
Gitblit v1.9.3