From 46de46ed851dc909f0ff355e9c6e3422efb5b4ad Mon Sep 17 00:00:00 2001
From: ludc
Date: 星期二, 30 四月 2024 14:27:10 +0800
Subject: [PATCH] 集成代码调整

---
 Source/UBCS/ubcs-service/ubcs-applyjtcodeservice/src/main/java/com/vci/ubcs/code/applyjtcodeservice/feigh/MdmInterJtClient.java |   67 ++++++++++++++++++++++++++++-----
 1 files changed, 57 insertions(+), 10 deletions(-)

diff --git a/Source/UBCS/ubcs-service/ubcs-applyjtcodeservice/src/main/java/com/vci/ubcs/code/applyjtcodeservice/feigh/MdmInterJtClient.java b/Source/UBCS/ubcs-service/ubcs-applyjtcodeservice/src/main/java/com/vci/ubcs/code/applyjtcodeservice/feigh/MdmInterJtClient.java
index 6bb3dad..df1435e 100644
--- a/Source/UBCS/ubcs-service/ubcs-applyjtcodeservice/src/main/java/com/vci/ubcs/code/applyjtcodeservice/feigh/MdmInterJtClient.java
+++ b/Source/UBCS/ubcs-service/ubcs-applyjtcodeservice/src/main/java/com/vci/ubcs/code/applyjtcodeservice/feigh/MdmInterJtClient.java
@@ -15,9 +15,9 @@
 import com.vci.ubcs.starter.util.MdmBtmTypeConstant;
 import com.vci.ubcs.starter.util.SaveLogUtil;
 import com.vci.ubcs.starter.web.util.VciBaseUtil;
-import lombok.AllArgsConstructor;
 import lombok.Data;
 import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.collections4.map.CaseInsensitiveMap;
 import org.jetbrains.annotations.NotNull;
 import org.springblade.core.tenant.annotation.NonDS;
 import org.springblade.core.tool.api.R;
@@ -29,6 +29,7 @@
 import org.springframework.web.bind.annotation.RestController;
 import springfox.documentation.annotations.ApiIgnore;
 
+import java.io.*;
 import java.util.*;
 import java.util.stream.Collectors;
 
@@ -43,7 +44,10 @@
 public class MdmInterJtClient implements IMdmInterJtClient {
 
 	@Value("${docking.apply.partCode:10}")
-	public String partCode;
+	private String partCode;
+
+	@Value("#{'${docking.apply.jDataBtmNames:wupin}'.split(',')}")
+	private List<String> JDATABTMNAMES;
 
 	/**
 	 * 闆嗗洟鐢宠鍗曟湇鍔�
@@ -195,6 +199,10 @@
 				dockingPreApplyFormList.add(dockingPreApplyForm);
 				String jdataid = dockingPreApplyForm.getDataOid();
 				String jdatabtmname = dockingPreApplyForm.getDataBtmName();
+				// 璺宠繃涓嶉渶瑕佸鐞嗛泦鍥㈣繑鐮佺殑鍒嗙被
+				if(!JDATABTMNAMES.contains(jdatabtmname)){
+					continue;
+				}
 				if (res) {
 					//姝ゅ闇�瑕佹煡璇笟鍔℃暟鎹紝鍘绘洿鏀�
 					R<List<BaseModel>> R = mdmEngineClient.selectByTypeAndOid(jdatabtmname,jdataid);
@@ -219,8 +227,9 @@
 								// 3.1銆侀�氳繃璇ユ潯鏁版嵁鐨勫垎绫籭d锛屾嬁鍒伴泦鍥㈠睘鎬ф槧灏勯厤缃紝鐢ㄦ潵灏嗛泦鍥㈢殑灞炴�ф槧灏勫埌鎴戜滑绯荤粺鐨勫睘鎬�
 								List<DockingPreAttrMapping> dockingPreAttrMappings = dockingPreAttrMappingService.selectByWrapper(Wrappers.<DockingPreAttrMapping>query().lambda().eq(DockingPreAttrMapping::getTargetClassifyId, codeclsfid).eq(DockingPreAttrMapping::getViewName,"缂栫爜瑙嗗浘"));
 								if(Func.isNotEmpty(dockingPreAttrMappings)){
+									log.info("寮�濮嬭皟鐢╯ourceAttrKey2TargetKey鏂规硶銆�");
 									//鏍规嵁闆嗗洟灞炴�ф槧灏勫皢闆嗗洟杞埌鎴戜滑绯荤粺锛屽苟淇敼涓嶄竴鑷寸殑鍒版垜浠郴缁熶腑瀵瑰簲鐨勮鏉¤褰曠殑鍊�
-									sourceAttrKey2TargetKey(dockingPreAttrMappings, viewValueList.get(0), oldDatalist, baseModel);
+									sourceAttrKey2TargetKey(dockingPreAttrMappings, viewValueList.get(0), baseModel);
 								}
 							}
 							log.info("鐢宠鍗�:"+applyId+",闆嗗洟鐮侊細"+customCoding+"缂栫爜锛�"+baseModel.getId());
@@ -246,6 +255,7 @@
 			return R.fail("闆嗗洟鐮侀泦鎴愯祴鍊煎け璐ワ紝鍘熷洜锛�"+e.getMessage());
 		}
 		log.info("鑾峰彇闆嗗洟闆嗗洟鐮侊紝璧嬪�煎埌涓绘暟鎹� end");
+
 		return R.success("闆嗗洟鐮佽祴鍊兼垚鍔�");
 	}
 
@@ -253,33 +263,70 @@
 	 * 鏍规嵁闆嗗洟灞炴�ф槧灏勫皢闆嗗洟杞埌鎴戜滑绯荤粺
 	 * @param dockingPreAttrMappings
 	 * @param viewValueMap
-	 * @param oldDatalist
 	 * @param baseModel
 	 */
-	private void sourceAttrKey2TargetKey(List<DockingPreAttrMapping> dockingPreAttrMappings,Map<String, Object> viewValueMap, List<BaseModel> oldDatalist,BaseModel baseModel){
-		Map<String, Object> targetKeyMap = new HashMap<>();
+	private void sourceAttrKey2TargetKey(List<DockingPreAttrMapping> dockingPreAttrMappings,Map<String, Object> viewValueMap,BaseModel baseModel) throws ServiceException {
+		log.info("寮�濮嬫牴鎹泦鍥㈠睘鎬ф槧灏勶紝灏嗛泦鍥㈠睘鎬ц浆鎴愮紪鐮佺郴缁熷睘鎬э紝骞惰繘琛屾槸鍚︿慨鏀圭殑姣斿锛�");
+		//娣辨嫹璐濊褰曚笅鍘熷璞★紝濡傛灉鏈夋洿鏀圭敤鏉ユ斁鍦ㄦ棫涓氬姟鏁版嵁瀛楁锛坥ldbusinessdata锛変笂
+		BaseModel oldBaseModel = null;
+		try {
+			oldBaseModel = deepCopy(baseModel);
+		} catch (Exception e) {
+			log.error("璁板綍鏃х殑涓氬姟鏁版嵁鏃讹紝baseModel瀵硅薄娣辨嫹璐濆嚭鐜伴敊璇紝鍘熷洜锛�"+e.getMessage());
+			e.printStackTrace();
+			throw new ServiceException("璁板綍鏃х殑涓氬姟鏁版嵁鏃讹紝baseModel瀵硅薄娣辨嫹璐濆嚭鐜伴敊璇紝鍘熷洜锛�"+e.getMessage());
+		}
+		Map<String, Object> targetKeyMap = new CaseInsensitiveMap<>();
 		// 灏嗛泦鍥㈠睘鎬ц浆鎴愭垜浠郴缁熷睘鎬х殑map
 		dockingPreAttrMappings.stream().forEach(item->{
 			targetKeyMap.put(item.getTargetAttrKey(),viewValueMap.get(item.getSourceAttrKey()));
 		});
 		// 姣斿baseModel鐨刣ata涓殑灞炴�ф槸鍚﹀拰targetKeyMap涓嶄竴鑷达紝涓嶄竴鑷寸殑璇濆氨闇�瑕佸皢baseModel鐨刣ata涓殑瀵瑰簲key鐨剉alue鍊艰浆鎴愰泦鍥㈢殑
 		boolean isEdit = false;
+		// 蹇界暐澶у皬鍐�
+		Map caseInsensitiveMap = new CaseInsensitiveMap(baseModel.getData());
 		for (Map.Entry<String, Object> entry : targetKeyMap.entrySet()) {
 			String key = entry.getKey();
 			Object targetValue = entry.getValue();
-			String dataValue = baseModel.getData().get(key);
-
+			String dataValue = String.valueOf(caseInsensitiveMap.get(key));
 			if (targetValue != null && !targetValue.equals(dataValue)) {
-				baseModel.getData().put(key, targetValue.toString());
+				caseInsensitiveMap.put(key, targetValue.toString());
 				isEdit = true;
 			}
 		}
 		// 闆嗗洟瀵规垜浠郴缁熷睘鎬у仛浜嗚皟鏁达紝鎴戜滑闇�瑕佸鑰佺殑涓氬姟鏁版嵁鍋氳褰�
 		if (isEdit) {
-			baseModel.getData().put("oldbusinessdata", JSON.toJSONString(oldDatalist));
+			log.info("闆嗗洟杩斿洖鐨勬暟鎹瓨鍦ㄥ樊寮傦紝寮�濮嬫墽琛屽缂栫爜绯荤粺basemodel瀵硅薄淇敼鎿嶄綔锛�");
+			// 娓呯┖鍘熷厛鐨刴ap锛屼娇鐢ㄦ柊鐨勪笉鍖哄垎key澶у皬鍐欑殑map
+			baseModel.getData().clear();
+			baseModel.getData().putAll(caseInsensitiveMap);
+			// 绉婚櫎鍘嗗彶鐨刼ldbusinessdata瀛楁锛屽惁鍒欎細瓒呴暱
+			oldBaseModel.getData().remove("oldbusinessdata");
+			baseModel.getData().put("oldbusinessdata", JSON.toJSONString(oldBaseModel));
 		}
 	}
 
+	/**
+	 * 娣辨嫹璐�
+	 * @param baseModel
+	 * @return
+	 * @throws ClassNotFoundException
+	 * @throws IOException
+	 */
+	public static BaseModel deepCopy(BaseModel baseModel) throws ClassNotFoundException, IOException {
+		ByteArrayOutputStream bos = new ByteArrayOutputStream();
+		ObjectOutputStream oos = new ObjectOutputStream(bos);
+		oos.writeObject(baseModel);
+		oos.close();
+
+		ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray());
+		ObjectInputStream ois = new ObjectInputStream(bis);
+		BaseModel copy = (BaseModel) ois.readObject();
+		ois.close();
+
+		return copy;
+	}
+
 	/***
 	 * 鎺ュ彈闆嗗洟鍒嗙被涓绘ā鍨嬫暟鎹�
 	 * @param dockingClassifyModelAttrVO

--
Gitblit v1.9.3