Source/UBCS/ubcs-service/ubcs-applyjtcodeservice/src/main/java/com/vci/ubcs/code/applyjtcodeservice/feigh/MdmInterJtClient.java
@@ -14,9 +14,11 @@
import com.vci.ubcs.starter.util.DefaultAttrAssimtUtil;
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;
@@ -28,6 +30,7 @@
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.annotations.ApiIgnore;
import java.io.*;
import java.util.*;
import java.util.stream.Collectors;
@@ -197,20 +200,35 @@
            if (res) {
               //此处需要查询业务数据,去更改
               R<List<BaseModel>> R = mdmEngineClient.selectByTypeAndOid(jdatabtmname,jdataid);
               // TODO:新增业务逻辑,需要根据集团返回的属性进行判断,如果集团对该属性进行了修改编码系统也就需要对属性进行修改
               if(R.isSuccess()){
                  List<BaseModel> oldDatalist=new ArrayList<>();
                  List<BaseModel> newDatalist=R.getData();
                  if(!CollectionUtils.isEmpty(newDatalist)){
                  List<BaseModel> newDatalist=new ArrayList<>();
                  List<BaseModel> oldDatalist=R.getData();
                  if(!CollectionUtils.isEmpty(oldDatalist)){
                     if(editObjectMap.containsKey(jdatabtmname)){
                        oldDatalist=editObjectMap.getOrDefault(jdatabtmname,new ArrayList<>());
                        newDatalist=editObjectMap.getOrDefault(jdatabtmname,new ArrayList<>());
                     }
                     BaseModel baseModel=oldDatalist.get(0);
                     //DefaultAttrAssimtUtil.updateDefaultAttrAssimt(baseModel);
                     baseModel.setLastModifyTime(new Date());
                     baseModel.getData().put("groupcode",customCoding);
                     baseModel.getData().put("GROUPCODE",customCoding);
                     // 1、取到集团返回的ViewInfos中编码视图中的属性
                     List<Map<String, Object>> viewValueList = mainData.getViewInfos().stream().filter(item -> item.getViewName().equals("编码视图")).map(DockingViewVO::getViewValue).findFirst().orElse(null);
                     // 2、比对属性是否和oldDatalist属性一致,不一致就需要更改
                     if(Func.isNotEmpty(viewValueList)){
                        // 3、需要将集团属性转换为我们系统的属性,再和我们系统的现有属性比对
                        String codeclsfid = VciBaseUtil.getMapStrValueIgnoreCase(baseModel.getData(),"CODECLSFID");
                        // 3.1、通过该条数据的分类id,拿到集团属性映射配置,用来将集团的属性映射到我们系统的属性
                        List<DockingPreAttrMapping> dockingPreAttrMappings = dockingPreAttrMappingService.selectByWrapper(Wrappers.<DockingPreAttrMapping>query().lambda().eq(DockingPreAttrMapping::getTargetClassifyId, codeclsfid).eq(DockingPreAttrMapping::getViewName,"编码视图"));
                        if(Func.isNotEmpty(dockingPreAttrMappings)){
                           log.info("开始调用sourceAttrKey2TargetKey方法。");
                           //根据集团属性映射将集团转到我们系统,并修改不一致的到我们系统中对应的该条记录的值
                           sourceAttrKey2TargetKey(dockingPreAttrMappings, viewValueList.get(0), baseModel);
                        }
                     }
                     log.info("申请单:"+applyId+",集团码:"+customCoding+"编码:"+baseModel.getId());
                     oldDatalist.add(baseModel);
                     editObjectMap.put(jdatabtmname,oldDatalist);
                     newDatalist.add(baseModel);
                     editObjectMap.put(jdatabtmname,newDatalist);
                  }
               }
            }
@@ -234,6 +252,74 @@
      return R.success("集团码赋值成功");
   }
   /**
    * 根据集团属性映射将集团转到我们系统
    * @param dockingPreAttrMappings
    * @param viewValueMap
    * @param baseModel
    */
   private void sourceAttrKey2TargetKey(List<DockingPreAttrMapping> dockingPreAttrMappings,Map<String, Object> viewValueMap,BaseModel baseModel) throws ServiceException {
      log.info("开始根据集团属性映射,将集团属性转成编码系统属性,并进行是否修改的比对!");
      //深拷贝记录下原对象,如果有更改用来放在旧业务数据字段(oldbusinessdata)上
      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的data中的属性是否和targetKeyMap不一致,不一致的话就需要将baseModel的data中的对应key的value值转成集团的
      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 = String.valueOf(caseInsensitiveMap.get(key));
         if (targetValue != null && !targetValue.equals(dataValue)) {
            caseInsensitiveMap.put(key, targetValue.toString());
            isEdit = true;
         }
      }
      // 集团对我们系统属性做了调整,我们需要对老的业务数据做记录
      if (isEdit) {
         log.info("集团返回的数据存在差异,开始执行对编码系统basemodel对象修改操作!");
         // 清空原先的map,使用新的不区分key大小写的map
         baseModel.getData().clear();
         baseModel.getData().putAll(caseInsensitiveMap);
         // 移除历史的oldbusinessdata字段,否则会超长
         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