xiejun
2025-01-22 d9183aa80ae17d36b79dda48c6b1d7fa22a80ee3
Source/UBCS/ubcs-service/ubcs-code/src/main/java/com/vci/ubcs/code/service/impl/CodeMdmInfaceImpl.java
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,909 @@
package com.vci.ubcs.code.service.impl;
import com.alibaba.cloud.commons.lang.StringUtils;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.vci.ubcs.code.bo.CodeClassifyFullInfoBO;
import com.vci.ubcs.code.constant.MdmDuckingConstant;
import com.vci.ubcs.code.dto.CodeOrderDTO;
import com.vci.ubcs.code.dto.CodeOrderSecDTO;
import com.vci.ubcs.code.entity.CodeClassify;
import com.vci.ubcs.code.entity.DockingLog;
import com.vci.ubcs.code.entity.DockingSystemConfig;
import com.vci.ubcs.code.enumpack.CodeDefaultLC;
import com.vci.ubcs.code.enumpack.CodeSecTypeEnum;
import com.vci.ubcs.code.enumpack.SysIntegrationDataFlowTypeEnum;
import com.vci.ubcs.code.enumpack.sysIntegrationPushTypeEnum;
import com.vci.ubcs.code.mapper.CommonsMapper;
import com.vci.ubcs.code.service.*;
import com.vci.ubcs.code.util.ClientBusinessObject;
import com.vci.ubcs.code.util.gennerAttrMapUtil;
import com.vci.ubcs.code.vo.pagemodel.*;
import com.vci.ubcs.code.vo.webserviceModel.apply.ApplyDataVO;
import com.vci.ubcs.code.vo.webserviceModel.apply.ApplyDatasVO;
import com.vci.ubcs.code.vo.webserviceModel.apply.ClassfyVO;
import com.vci.ubcs.code.vo.webserviceModel.apply.ProppertyVO;
import com.vci.ubcs.code.vo.webserviceModel.attrmap.*;
import com.vci.ubcs.code.vo.webserviceModel.mdm.MDMParamData;
import com.vci.ubcs.code.vo.webserviceModel.mdm.MdmResultData;
import com.vci.ubcs.code.vo.webserviceModel.person.EnumerableData;
import com.vci.ubcs.code.vo.webserviceModel.person.PersonMasterData;
import com.vci.ubcs.code.vo.webserviceModel.person.ResultMdMapping;
import com.vci.ubcs.code.vo.webserviceModel.result.xml.XMLResultDataObjectDetailDO;
import com.vci.ubcs.code.webService.config.AttributeMapConfig;
import com.vci.ubcs.code.webService.config.ClassifyConfig;
import com.vci.ubcs.code.webService.config.MDMInterFaceConfig;
import com.vci.ubcs.omd.feign.IBtmTypeClient;
import com.vci.ubcs.omd.vo.BtmTypeVO;
import com.vci.ubcs.starter.util.DefaultAttrAssimtUtil;
import com.vci.ubcs.starter.web.util.BeanUtilForVCI;
import com.vci.ubcs.starter.web.util.VciBaseUtil;
import lombok.extern.slf4j.Slf4j;
import org.springblade.core.log.exception.ServiceException;
import org.springblade.core.secure.BladeUser;
import org.springblade.core.secure.utils.AuthUtil;
import org.springblade.core.tool.api.R;
import org.springblade.core.tool.utils.Func;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import javax.annotation.Resource;
import javax.jws.WebMethod;
import javax.servlet.http.HttpServletRequest;
import javax.xml.ws.WebServiceContext;
import javax.xml.ws.handler.MessageContext;
import java.math.BigDecimal;
import java.sql.Timestamp;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.ForkJoinPool;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicReference;
import java.util.stream.Collectors;
import static com.vci.ubcs.code.constant.MdmEngineConstant.CODE_SEC_LENGTH_FIELD;
import static com.vci.ubcs.code.constant.MdmEngineConstant.DEFAULT_SYNC_ATTR_LIST;
import static com.vci.ubcs.code.enumpack.CodeSecTypeEnum.CODE_SERIAL_SEC;
/***
 * ç»Ÿä¸€æŽ¥å£
 */
@Service
@Slf4j
public class CodeMdmInfaceImpl implements CodeMdmInfaceI {
   @Autowired(required = false)
   private AttributeMapConfig attributeMapConfig;
   /****
    * å…³äºŽè·ŸMDM集成配置
    */
   @Autowired(required = false)
   private MDMInterFaceConfig mdmInterFaceConfig;
   /**
    * ä¸»é¢˜åº“分类的服务
    */
   @Autowired(required = false)
   private ICodeClassifyService classifyService;
   /**
    * ä¸šåŠ¡ç±»åž‹çš„æœåŠ¡
    */
   @Autowired
   private IBtmTypeClient btmTypeClient;
   /**
    * é€šç”¨æŸ¥è¯¢
    */
   @Resource
   private CommonsMapper commonsMapper;
   /**
    * ä¸»æ•°æ®å¼•擎的服务
    */
   @Resource
   private MdmEngineService engineService;
   /**
    * å¯†çº§çš„æœåŠ¡
    */
   @Resource
   private MdmIOService mdmIOService;
   @Resource
   private IDockingSystemConfigService dockingSystemConfigService;
   /***
    * é›†æˆæŽ¥å£æ—¥å¿—服务的配置
    */
   @Resource
   private IDockingLogeService dockingLogeService;
   @Resource
   private IPasswordFreeLoginService passwordFreeLoginService;
   /***
    * æ˜¯å¦æ ¡éªŒæŽ¥å£ç®¡ç†
    */
   @Value("${code.universalinterface.checkSystemConfig:true}")
   public boolean CODE_CHECKCONFIG;
   /**
    * è‡ªå®šä¹‰å¹¶å‘ForkJoinPool
    */
   private static final ForkJoinPool customForkJoinPool = new ForkJoinPool(Runtime.getRuntime().availableProcessors() - 1);
   private  static String separator="##VCI##";
   private  String errorid="0";
   private String msg="成功";
   private  String objerrorCode="0";
   private String objerrorMsg="成功";
   private final ThreadLocal<HttpServletRequest> threadLocal = new ThreadLocal<>();
   @Resource
   private WebServiceContext webServiceContext;
   @Override
   public void setThreadLocal(ThreadLocal<HttpServletRequest> requestThreadLocal){
      this.threadLocal.set(requestThreadLocal.get());
      requestThreadLocal.remove();
   }
   @WebMethod
   private HttpServletRequest getRequest() {
      //rest请求方式获取request
      HttpServletRequest request = this.threadLocal.get();
      if(Func.isEmpty(request)){
         try {
            // webservice请求方式获取HttpServletRequest对象
            request = (HttpServletRequest)webServiceContext.getMessageContext().get(MessageContext.SERVLET_REQUEST);
         }catch (Exception e){
            e.printStackTrace();
            log.error("获取httpServletRequest失败,原因:***********:",e);
            throw new ServiceException("获取httpServletRequest失败,原因:"+e.getMessage());
         }
      }else {
         this.threadLocal.remove();
      }
      return request;
   }
   @Override
   public MdmResultData syncDataForMDM(MDMParamData mdmParamData,String library,String classifyCode) {
      boolean isCodeOrGroupCode=false;
      MdmResultData mdmResultData=new MdmResultData();
      String systemCode=mdmParamData.getSystemCode();
      List<ResultMdMapping> resultMdMappingList=new ArrayList<>();
      String message="";
      AtomicBoolean success = new AtomicBoolean(true);
      List<Map<String,Object>> masterDataList = new ArrayList<>();
      AtomicReference<ClassifyConfig> currentClassifyConfig = new AtomicReference<>(new ClassifyConfig());
      try {
         if (mdmParamData == null) {
            throw new Throwable("传入参数为null");
         }
         try {
            passwordFreeLoginService.pwdFreeLoginByBoolean(systemCode.toLowerCase(), this.getRequest());
         } catch (Throwable e) {
            throw new Throwable("用户鉴权失败");
         }
         List<ClassifyConfig> classifyConfigList=mdmInterFaceConfig.getClassifyconfigs();
         //masterDataList
         String masterDataStr = mdmParamData.getMasterData();
         masterDataList = JSONArray.parseObject(masterDataStr,List.class);
         if(StringUtils.isNotBlank(library)&&StringUtils.isNotBlank(classifyCode)){
            String finalLibrary = library;
            classifyConfigList.stream().forEach(classifyConfig -> {
               String  currentClassifyCode=classifyConfig.getClassCode();
               String currentLibrary=classifyConfig.getLibrary();
               if(finalLibrary.equals(currentLibrary)&&classifyCode.equals(currentClassifyCode)){
                  currentClassifyConfig.set(classifyConfig);
               }
            });
         }else{
            Map<String,List<ClassifyConfig>> fieldClassifyConfigMap=new HashMap<>();
            classifyConfigList.stream().forEach(classifyConfig -> {
               String sourceKey=classifyConfig.getSourceKey();//分类标识字段
               //String sourceClassifyCode=classifyConfig.getSourceClassifyCode();//分类标识
               List<ClassifyConfig> classifyConfigs = new ArrayList<>();
               if(fieldClassifyConfigMap.containsKey(sourceKey)) {
                  List<ClassifyConfig> oldClassifyConfigs=   fieldClassifyConfigMap.get(sourceKey);
                  classifyConfigs.addAll(oldClassifyConfigs);
               }
               classifyConfigs.add(classifyConfig);
               fieldClassifyConfigMap.put(sourceKey,classifyConfigs);
            });
            masterDataList.stream().forEach(masterData -> {
                  masterData.forEach((field, vaule) -> {
                     String newValue="";
                     if (fieldClassifyConfigMap.containsKey(field)) {
                        //vaule=StringUtils.isBlank(vaule) ? "" : vaule;
                        newValue=objectToStr(vaule);
                        List<ClassifyConfig> classifyConfigs = fieldClassifyConfigMap.get(field);
                        Map<String, ClassifyConfig> classifyConfigMap = classifyConfigs.stream().filter(classify -> classify != null && StringUtils.isNotBlank(classify.getSourceClassifyCode())).collect(Collectors.toList()).stream().collect(Collectors.toMap(s -> s.getSourceClassifyCode(), t -> t));
                        if (classifyConfigMap.containsKey(newValue)) {
                           currentClassifyConfig.set(classifyConfigMap.get(newValue));
                        }
                     }
                  });
            });
         }
         library= currentClassifyConfig.get().getLibrary();
         if (StringUtils.isBlank(library)) {
            success.set(false);
            log.info("与MDM集成配置缺少库节点信息,library->" + library);
            throw new Throwable("与MDM集成配置缺少库节点信息,library->" + library);
         }
         String classCode= currentClassifyConfig.get().getClassCode();
         ClassfyVO classfyVO = new ClassfyVO();
         classfyVO.setLibrary(library);
         classfyVO.setClassCode(classCode);
         CodeClassifyVO codeClassifyVO = this.getClassfy(classfyVO, library);
         log.info("end:分类查询完毕");
         //获取分类模板信息
         if (codeClassifyVO == null || StringUtils.isBlank(codeClassifyVO.getOid())) {
            success.set(false);
            throw new Throwable("根据配置分类的分类编号,未获取到分类信息");
         }
         CodeClassifyTemplateVO templateVO = engineService.getUsedTemplateByClassifyOid(codeClassifyVO.getOid());
         if (templateVO == null || StringUtils.isBlank(templateVO.getOid())) {
            success.set(false);
            throw new Throwable("根据传输的分类,未获取MDM系统中对应模板");
         }
         if(CODE_CHECKCONFIG) {
            //校验是否配置
            DockingSystemConfig dockingSystemConfig=null;
            dockingSystemConfig=checkIspass(systemCode, SysIntegrationDataFlowTypeEnum.ACCEPT.getValue(), sysIntegrationPushTypeEnum.ACCPET_APPCODE.getValue(),codeClassifyVO.getOid());
            if(dockingSystemConfig==null||StringUtils.isBlank(dockingSystemConfig.getOid())){
               throw new Throwable("系统标识为【"+ systemCode +"】,集成分类为【"+codeClassifyVO.getName()+"】以上分类,"+sysIntegrationPushTypeEnum.ACCPET_APPCODE.getText()+"接口配置已停用或者未配置,请联系编码管理员!");
            }
            isCodeOrGroupCode="true".equals(dockingSystemConfig.getIsGroupCodeFlag())?true:false;
         }
         List<CodeClassifyTemplateAttrVO> attrVOS = templateVO.getAttributes().stream().filter(s -> !DEFAULT_SYNC_ATTR_LIST.contains(s.getId()) &&
            ((Func.isNotEmpty(s.getClassifyInvokeAttr()) || Func.isNotEmpty(s.getClassifyInvokeAttrName())) || VciBaseUtil.getBoolean(s.getFormDisplayFlag()))
         ).collect(Collectors.toList());
         R<BtmTypeVO> r = btmTypeClient.getAllAttributeByBtmId(templateVO.getBtmTypeId());
         if (!r.isSuccess()) {
            throw new Throwable(r.getMsg());
         }
         BtmTypeVO btmTypeVO = r.getData();
         if (btmTypeVO == null) {
            throw new Throwable("根据业务类型未查询到业务类型对象!");
         }
         String tableName = btmTypeVO.getTableName();
         if (com.alibaba.nacos.common.utils.StringUtils.isBlank(tableName)) {
            throw new Throwable("根据业务类型未查询到业务类型相关联的表");
         }
         List<String> codeList = new ArrayList<>();
         List<ApplyDataVO> applyDataVOList = new ArrayList<>();
         List<ApplyDataVO> deleteDataVOList = new ArrayList<>();
         List<String> fields = Func.toStrList(currentClassifyConfig.get().getEnumFields());
         masterDataList.stream().forEach(masterData -> {
            ApplyDataVO object = new ApplyDataVO();
            List<ProppertyVO> proppertyVOList = new ArrayList<>();
            masterData.forEach((field, vaule) -> {
               /***
                * æ ¹æ®é…ç½®æ–‡ä»¶èŽ·å–æžšä¸¾å€¼
                */
               String newValue=objectToStr(vaule);
               if(fields.contains(field)){//如果是枚举,则需要转换枚举值
                  String enumFiled = newValue;
                  EnumerableData enumerableData = JSONObject.toJavaObject(JSONObject.parseObject(enumFiled), EnumerableData.class);
                  String enumCode = enumerableData.getCode();
                  //String enumCodeValue=enumerableData.getName();
                  ProppertyVO proppertyVO = new ProppertyVO();
                  proppertyVO.setKey(field);
                  proppertyVO.setValue(enumCode);
                  proppertyVOList.add(proppertyVO);
               }else {
                  ProppertyVO proppertyVO = new ProppertyVO();
                  proppertyVO.setKey(field);
                  proppertyVO.setValue(newValue);
                  proppertyVOList.add(proppertyVO);
               }
            });
            Map<String,String> fixedFieldMap = currentClassifyConfig.get().getFixedFieldMap();
            if(fixedFieldMap.containsKey("creator")){
               String fixedField=fixedFieldMap.getOrDefault("creator","");
               object.setCreator(masterData.getOrDefault(fixedField,"").toString());//创建者
            }
            if(fixedFieldMap.containsKey("modifier")) {
               String fixedField=fixedFieldMap.getOrDefault("modifier","");
               object.setEditor(masterData.getOrDefault(fixedField, "").toString());//修改者
            }
            if(fixedFieldMap.containsKey("id")) {
               String fixedField=fixedFieldMap.getOrDefault("id","");
               object.setId(masterData.getOrDefault(fixedField, "").toString());//主键
            }
            object.setStatus(CodeDefaultLC.RELEASED.getValue());//状态则需要判断
            String dr="0";
            if(fixedFieldMap.containsKey("dr")) {
               String fixedField=fixedFieldMap.getOrDefault("dr","");
               dr = masterData.getOrDefault(fixedField, "").toString();
            }
            List<String> sourceCodeKeyList=VciBaseUtil.str2List(currentClassifyConfig.get().getSourceCodeKey());
            //object.setCode(masterData.getOrDefault(currentClassifyConfig.get().getSourceCodeKey(),"").toString());//编码
            if(!CollectionUtils.isEmpty(sourceCodeKeyList)) {
               sourceCodeKeyList.stream().forEach(codekey -> {
                  if (StringUtils.isNotBlank(masterData.getOrDefault(codekey, "").toString())) {
                     object.setCode(masterData.getOrDefault(codekey, "").toString());//编码
                  }
               });
            }
            object.setProp(proppertyVOList);
            if (dr.equals(1)) {
               //操作类型
               object.setOperate("delete");
               deleteDataVOList.add(object);
            } else {
               //String worker_category=personMasterData.getWorker_category();
               object.setOperate("create");
               applyDataVOList.add(object);
            }
            codeList.add(object.getCode());
         });
         if(CollectionUtils.isEmpty(codeList)){
            throw  new Throwable("检查配置文件:【sourceCodeKey】,唯一标识字段是否正确");
         }
         String targetCodeKey=currentClassifyConfig.get().getTargetCodeKey();
         StringBuffer sb = new StringBuffer();
         sb.append(" select * from ");
         sb.append(tableName);
         sb.append(" where 1=1 ");
         sb.append(" and lastr=1 and lastv=1");
         sb.append(" and "+targetCodeKey+" in (");
         sb.append(VciBaseUtil.toInSql(codeList.toArray(new String[0])));
         sb.append(")");
         List<Map<String, String>> dataMapList = commonsMapper.queryByOnlySqlForMap(sb.toString());
         DefaultAttrAssimtUtil.mapToLowerCase(dataMapList, true);
         List<ClientBusinessObject> cboList = ChangeMapTOClientBusinessObjects(dataMapList);
         ApplyDatasVO applyDatasVO = new ApplyDatasVO();
         ApplyDatasVO editDatasVO = new ApplyDatasVO();
         if (!CollectionUtils.isEmpty(cboList)) {
            //根据MDM编码去判断数据是否重复.
            Map<String, ClientBusinessObject> oldpplyDataVOMap = cboList.stream().filter(data -> data != null && StringUtils.isNotBlank(data.getAttributeValue(targetCodeKey))).collect(Collectors.toList()).stream().collect(Collectors.toMap(s -> s.getAttributeValue(targetCodeKey), t -> t));
            //数据库不存在的
            List<ApplyDataVO> applyApplyDataVOList = applyDataVOList.stream().filter(cbo -> {
               String code = cbo.getCode();
               return !oldpplyDataVOMap.containsKey(code);
            }).collect(Collectors.toList());
            applyDatasVO.setObject(applyApplyDataVOList);
            //数据库存在的
            List<ApplyDataVO> editApplyDataVOList = applyDataVOList.stream().filter(cbo -> {
               String code = cbo.getCode();
               if (oldpplyDataVOMap.containsKey(code)) {
                  ClientBusinessObject object=   oldpplyDataVOMap.get(code);
                  cbo.setCode(object.getId());
                  cbo.setOperate("update");
               }
               return oldpplyDataVOMap.containsKey(code);
            }).collect(Collectors.toList());
            editApplyDataVOList.addAll(deleteDataVOList);
            editDatasVO.setObject(editApplyDataVOList);
         } else {
            applyDatasVO.setObject(applyDataVOList);
         }
         LinkedList<XMLResultDataObjectDetailDO> resultDataObjectDetailDOs = new LinkedList<>();
         if (editDatasVO.getObject() != null && editDatasVO.getObject().size() > 0) {
            DataObjectVO dataObjectVO = new DataObjectVO();
            this.getConfigDatas(systemCode, library, editDatasVO, attrVOS, dataObjectVO);
            log.info("start:修改数据执行完毕");
            //boolean personApplyGroupCode = personAndDeptConfig.isPersonApplyGroupCode();
            mdmIOService.batchSyncEditDatas(codeClassifyVO, dataObjectVO, resultDataObjectDetailDOs, isCodeOrGroupCode);
            log.info("end:修改数据执行完毕");
         }
         if (applyDatasVO.getObject() != null && applyDatasVO.getObject().size() > 0) {
            DataObjectVO dataObjectVO = new DataObjectVO();
            this.getConfigDatas(systemCode, library, applyDatasVO, attrVOS, dataObjectVO);
            CodeClassifyFullInfoBO classifyFullInfo = classifyService.getClassifyFullInfo(codeClassifyVO.getOid());
            CodeRuleVO ruleVO = engineService.getCodeRuleByClassifyFullInfo(classifyFullInfo);
            if (ruleVO == null || "".equals(ruleVO.getOid())) {
               throw new Throwable("编码规则");
            }
            List<XMLResultDataObjectDetailDO> xDOs = new CopyOnWriteArrayList<>();
            final List<RowDatas> rowDatas = dataObjectVO.getRowData();
            boolean finalIsCodeOrGroupCode = isCodeOrGroupCode;
            rowDatas.parallelStream().forEach(rowData -> {
               String mesg = "";
               try {
                  CodeOrderDTO orderDTO = new CodeOrderDTO();
                  List<CodeOrderSecDTO> codeOrderSecDTOList = new ArrayList<>();
                  orderDTO.setCodeClassifyOid(codeClassifyVO.getOid());//分类主键
                  orderDTO.setTemplateOid(templateVO.getOid());
                  orderDTO.setCreator(rowData.getCreator());
                  orderDTO.setLastModifier(rowData.getEditor());
                  orderDTO.setLcStatus(rowData.getStatus());
                  if (!CollectionUtils.isEmpty(ruleVO.getSecVOList())) {//算规则
                     boolean usedFlag=currentClassifyConfig.get().isUsedFlag();//是否依据编码规则
                     String codeFilter=currentClassifyConfig.get().getCodeFilter();//根据编码值截取
                     if(usedFlag){//如果依据MDM编码为编码系统编码的话,则根据认为是可变码段
                        if(ruleVO.getSecVOList().size()==1) {
                           ruleVO.getSecVOList().stream().forEach(codeBasicSecVO -> {
                              if (codeBasicSecVO.getSecType().equals("codevariablesec")) {//规则之定义为可变码段存储主数据传递过来的数据
                                 CodeOrderSecDTO CodeOrderSecDTO = new CodeOrderSecDTO();
                                 CodeOrderSecDTO.setSecOid(codeBasicSecVO.getOid());
                                 CodeOrderSecDTO.setSecValue(rowData.getCode());
                                 codeOrderSecDTOList.add(CodeOrderSecDTO);
                              }
                           });
                        }else{
                           mesg="根据配置编码依据集成系统:["+systemCode+"]的数据编码为依据,编码规则应为可变码段";
                           new Throwable("根据配置编码依据集成系统:["+systemCode+"]的数据编码为依据,编码规则应为可变码段");
                        }
                     }else {//如果不依据MDM编码为编码系统编码的话,则根据配置生成编码规则
                        String[] secValues = currentClassifyConfig.get().getSecValueFilter().split("#");
                        final int[] index = {0};
                        try {
                           ruleVO.getSecVOList().stream().forEach(codeBasicSecVO -> {
                              if (!CODE_SERIAL_SEC.getValue().equals(codeBasicSecVO.getSecType())) {
                                 CodeOrderSecDTO CodeOrderSecDTO = new CodeOrderSecDTO();
                                 CodeOrderSecDTO.setSecOid(codeBasicSecVO.getOid());
                                 CodeOrderSecDTO.setSecValue(secValues[index[0]]);
                                 codeOrderSecDTOList.add(CodeOrderSecDTO);
                                 index[0]++;
                              }
                           });
                        }catch (Throwable e){
                           mesg="计算码段码值出现异常:"+e.getMessage();
                           e.printStackTrace();
                           log.error("计算码段码值出现异常,原因:***********:",e);
                           new Throwable("计算码段码值出现异常:"+e.getMessage());
                        }
                     }
                  }
                  if(CollectionUtils.isEmpty(codeOrderSecDTOList)){
                     throw  new Exception(mesg);
                  }
                  orderDTO.setCodeRuleOid(ruleVO.getOid());
                  orderDTO.setSecDTOList(codeOrderSecDTOList);//存储编码
                  orderDTO.setData(rowData.getFiledValue());
                  String code = engineService.addSaveCodeNotauthUser(orderDTO, false);
                  if (StringUtils.isNotBlank(code)) {
                     StringBuffer sqlsb = new StringBuffer();
                     sqlsb.append(" select * from ");
                     sqlsb.append(tableName);
                     sqlsb.append(" where 1=1 ");
                     sqlsb.append(" and lastr=1 and lastv=1");
                     sqlsb.append(" and id in (");
                     sqlsb.append(VciBaseUtil.toInSql(code));
                     sqlsb.append(")");
                     List<Map<String, String>> newDataMapList = commonsMapper.queryByOnlySqlForMap(sqlsb.toString());
                     if (!CollectionUtils.isEmpty(newDataMapList)) {
                        String oid = StringUtils.isBlank(newDataMapList.get(0).get("OID")) ? "" : newDataMapList.get(0).get("OID");
                        List<String> oidList = new ArrayList<>();
                        oidList.add(oid);
                        //如果有申请就去调用申请集团码
                        if (finalIsCodeOrGroupCode) {
                           mdmIOService.sendApplyGroupcode(oidList, templateVO.getBtmTypeId(), sysIntegrationPushTypeEnum.ACCPET_APPCODE.getValue());
                           success.set(true);
                           mesg = "数据保存成功,等待申请集团码";
                        }
                     }
                  }
               } catch (Exception e) {
                  log.error("集成系统:【"+systemCode+"】申请编码失败:,原因:***********:",e);
                  mesg="集成系统:【"+systemCode+"】申请编码失败:" + e.getMessage();
                  mesg = e.getMessage();
                  e.printStackTrace();
               //   throw new ServiceException(e.getMessage());
               } finally {
                  XMLResultDataObjectDetailDO x = new XMLResultDataObjectDetailDO();
                  x.setId(rowData.getOid());
                  x.setCode(rowData.getCode());
                  x.setMsg(mesg);
                  x.setErrorid("1");
                  xDOs.add(x);
               }
            });
            resultDataObjectDetailDOs.addAll(xDOs);
            boolean finalSuccess1 = success.get();
            String finalMessage1 = message;
            // é™åˆ¶çº¿ç¨‹å¹¶è¡Œæ•°é‡
            customForkJoinPool.submit(() -> {
               resultDataObjectDetailDOs.stream().forEach(resultDataObjectDetailDO -> {
                  ResultMdMapping resultMdMapping = new ResultMdMapping();
                  resultMdMapping.setBusiDataId(resultDataObjectDetailDO.getId());
                  resultMdMapping.setSuccess(finalSuccess1);
                  resultMdMapping.setEntityCode(" ");
                  resultMdMapping.setMdmCode(resultDataObjectDetailDO.getCode());
                  resultMdMapping.setMessage(finalMessage1);
                  resultMdMapping.setSubMdMappings(null);
                  resultMdMappingList.add(resultMdMapping);
               });
            }).join();
            log.info("end:申请获取完毕");
         }
      } catch (Throwable e) {
         e.printStackTrace();
         log.error("集成系统:【"+systemCode+"】执行集成失败:",e);
         success.set(false);
         message = "集成系统:【"+systemCode+"】执行集成失败:" + e.getMessage();
         msg ="集成系统:【"+systemCode+"】执行集成失败" + e.getMessage();
         //组织返回结果
         boolean finalSuccess = success.get();
         String finalMessage = message;
         masterDataList.stream().forEach(masterData -> {
            Map<String, String> dataMap = VciBaseUtil.objectToMapString(masterData);
            ResultMdMapping resultMdMapping = new ResultMdMapping();
            resultMdMapping.setBusiDataId(dataMap.getOrDefault("id",""));
            resultMdMapping.setSuccess(finalSuccess);
            resultMdMapping.setEntityCode(" ");
            resultMdMapping.setMdmCode(dataMap.getOrDefault(currentClassifyConfig.get(),""));
            resultMdMapping.setMessage(finalMessage);
            resultMdMapping.setSubMdMappings(null);
         });
      } finally {
         mdmResultData.setMessage(message);
         mdmResultData.setSuccess(success.get());
         mdmResultData.setMdMappings(resultMdMappingList);
         //Object object = JSONObject.toJSON(resultOrgData);
      }
      String resultStr = JSONObject.toJSONString(mdmResultData);
      String data = JSONObject.toJSONString(mdmParamData);
      try {
         //记录日志
         this.saveLogs(systemCode, systemCode, data, resultStr, success.get(), msg, "syncDataForMDM");
      } catch (Throwable e) {
         log.error("保存日志出错,原因:",e);
         e.printStackTrace();
      }
      return mdmResultData;
   }
   private List<ClientBusinessObject> ChangeMapTOClientBusinessObjects(List<Map<String,String>> oldDataMap){
      List<ClientBusinessObject> clientBusinessObjectList=new ArrayList<>();
      DefaultAttrAssimtUtil.mapToLowerCase(oldDataMap,true);
      final BladeUser user = AuthUtil.getUser();
      oldDataMap.stream().forEach(dataMap->{
         ClientBusinessObject clientBusinessObject=new ClientBusinessObject();
         DefaultAttrAssimtUtil.copplyDefaultAttrAssimt(dataMap,clientBusinessObject,false,user);
         for (String key:dataMap.keySet()){
            Object value= dataMap.getOrDefault(key,"");
            clientBusinessObject.setAttributeValue(key.toLowerCase(Locale.ROOT),value==null?"":value.toString());
         }
         clientBusinessObjectList.add(clientBusinessObject);
      });
      return clientBusinessObjectList;
   }
   /***
    * æŸ¥è¯¢æ ¡éªŒåˆ†ç±»ä¿¡æ¯
    * @param classfyVO
    */
   private  CodeClassifyVO getClassfy(ClassfyVO classfyVO,String libray) throws Throwable{
      CodeClassifyVO classifyVO = new CodeClassifyVO();
      try {
         String classCode = classfyVO.getClassCode();
         String className = classfyVO.getFullclsfNamePath();
         //根据分类代号查询分类信息
         if (StringUtils.isNotBlank(classfyVO.getClassCode())) {
            Map<String, String> conditionMap = new HashMap<>();
            List<CodeClassify> codeClassifyList = classifyService.selectByWrapper(Wrappers.<CodeClassify>query().lambda().eq(CodeClassify::getId, classCode));
            final CodeClassify[] newCodeClassify = {new CodeClassify()};
            if (!CollectionUtils.isEmpty(codeClassifyList)) {
               codeClassifyList.stream().forEach(codeClassify -> {
                  CodeClassifyVO codeClassifyVO=  classifyService.getTopClassifyVO(codeClassify.getOid());
                  if(codeClassifyVO.getId().toUpperCase(Locale.ROOT).equals(libray.toUpperCase(Locale.ROOT))){
                     newCodeClassify[0] =codeClassify;
                  }
               });
               classifyVO = new CodeClassifyVO();
               BeanUtilForVCI.copyPropertiesIgnoreCase(newCodeClassify[0], classifyVO);
               //将DTO转换为DO
               if(StringUtils.isBlank(classifyVO.getOid())){
                  throw new  Throwable("申请编码的分类:【"+classCode+"】不属于库节点【"+libray+"】,请检查参数分类节点/库节点信息是否匹配");
               }
            }else{
               throw new  Throwable("根据分类代号未查询到相应的分类信息");
            }
         } else {
            classifyVO = classifyService.getObjectByClsfNamePath(className.replace(separator, "/"));
            if(StringUtils.isBlank(classifyVO.getOid())){
               throw new  Throwable("根据分类名称路径未查询到相应的分类信息");
            }
         }
      }catch (Throwable e){
         objerrorCode="100";
         log.error("获取分类信息失败:",e);
         e.printStackTrace();
         throw    new  Throwable("获取分类信息失败:"+e.getMessage());
      }
      return classifyVO;
   }
   public void getConfigDatas(String systemId,String libray, ApplyDatasVO applyDatasVO,List<CodeClassifyTemplateAttrVO> codeClassifyTemplateAttrVOList,DataObjectVO dataObjectVO) throws Throwable {
      LinkedHashMap<String,LinkedHashMap<String,String>> dataKeyValueMap=new LinkedHashMap<>();
      //如果将数据转换成所需要的数据对象
      Map<String, String> attrMapConfigMap=new HashMap<>();
      Map<String, String> propMaps=new HashMap<>();
      log.info("开始读取系统配置文件 start");
      Map<String, String> stringStringMap=attributeMapConfig.getSystem_attrmap();
      log.info("集成系统属性映射配置文件条目数-》"+stringStringMap.size());
      if(!CollectionUtils.isEmpty(stringStringMap)) {
         List<LibraryClsfDO> libraryClsfDOList=new ArrayList<>();
         try {
            log.info("info:需要读取配置文件");
            LibraryDO libraryDO = gennerAttrMapUtil.getNewInstance().gennerAttrMapBySystem(systemId, stringStringMap);
            libraryClsfDOList = libraryDO.getClsf();
         } catch (Throwable e) {
            objerrorCode = "1";
            e.printStackTrace();
            log.error("集成系统标识为:【" + systemId + "】,分类库为:【" + libray + "】的集成属性配置文件读取失败",e);
            throw new Throwable("集成系统标识为:【" + systemId + "】,分类库为:【" + libray + "】的集成属性配置文件读取失败");
         }
         // String path = stringStringMap.get(systemId);
         // å¿½ç•¥key大小写,获取配置的映射文件路径
         String path = VciBaseUtil.getMapStrValueIgnoreCase(stringStringMap,systemId);
         if (!CollectionUtils.isEmpty(libraryClsfDOList)) {
            Map<String, List<ClsfAttrMappingDO>> libPropMaps = libraryClsfDOList.stream().collect(Collectors.toMap(LibraryClsfDO::getLibrary, LibraryClsfDO::getProp, (key1, key2) -> key2));
            log.info("根据参数:libray:-》" + libray + "从配置文件中找对应属性映射配置");
            if (libPropMaps.containsKey(libray.toUpperCase(Locale.ROOT))) {
               log.info("根据参数:libray:-》" + libray + "匹配到相应的属性映射信息");
               List<ClsfAttrMappingDO> clsfAttrMappingDOList = libPropMaps.get(libray.toUpperCase(Locale.ROOT));
               propMaps = clsfAttrMappingDOList.stream().collect(Collectors.toMap(ClsfAttrMappingDO::getSourceKey, ClsfAttrMappingDO::getTargetKey, (key1, key2) -> key2));
               log.info("根据参数:libray:-》" + libray + "匹配到相应的属性映射信息,属性映射条目数+" + clsfAttrMappingDOList.size());
            } else {
               objerrorCode = "1";
               throw new Throwable("根据系统标识【" + systemId + "】找到对应的配置文件:【" + path + "】,但未获取到对应的库【" + libray + "】属性映射信息配置");
            }
         }else{
            objerrorCode = "1";
            throw new Throwable("根据系统标识【" + systemId + "】找到对应的配置文件:【" + path + "】,但未获取到对应的库【" + libray + "】属性映射信息配置");
         }
      }else{
         objerrorCode = "1";
         throw new Throwable("未获取到集成属性映射系统配置信息");
      }
      log.info("根据参数:libray:-》"+libray+"从配置文件中找对应属性映射配置 end ");
      LinkedList<String> rowNameList=new LinkedList<>();
      LinkedHashMap<String,Integer> filedIndexMap=new LinkedHashMap<>();
      //根据分类模板组织数据
      final int[] index = {0};
      try {
         //除去默认的属性.还有只有具有分类注入的才过滤出来
         codeClassifyTemplateAttrVOList = codeClassifyTemplateAttrVOList.stream().filter(
            s ->!DEFAULT_SYNC_ATTR_LIST.contains(s.getId()) &&
               ((Func.isNotEmpty(s.getClassifyInvokeAttr()) || Func.isNotEmpty(s.getClassifyInvokeAttrName())) || VciBaseUtil.getBoolean(s.getFormDisplayFlag()))
         ).collect(Collectors.toList());
         codeClassifyTemplateAttrVOList.stream().forEach(codeClassifyTemplateAttrVO -> {
            String attrName = codeClassifyTemplateAttrVO.getName();
            String field = codeClassifyTemplateAttrVO.getId();
            rowNameList.add(attrName);
            filedIndexMap.put(field, index[0]++);
         });
         dataObjectVO.setColName(rowNameList);//放入属性
         attrMapConfigMap.putAll(propMaps);
         LinkedList<RowDatas> rowDataList = new LinkedList<>();
         List<ApplyDataVO> applyDataVOList=new ArrayList<>();
         if(!CollectionUtils.isEmpty(applyDatasVO.getObject())){
            applyDataVOList=applyDatasVO.getObject();
         }
         //Map<String, List<ProppertyVO>> dataPropMap = applyDataVOList.stream().collect(Collectors.toMap(ApplyDataVO::getId, ApplyDataVO::getProp, (key1, key2) -> key2));
         final int[] rowIndex = {0};
         applyDataVOList.stream().forEach(applyDataVO -> {
            rowIndex[0]++;
            RowDatas rowDatas = new RowDatas();
            rowDatas.setOid(applyDataVO.getId());
            rowDatas.setCreator(applyDataVO.getCreator());
            rowDatas.setEditor(applyDataVO.getEditor());
            rowDatas.setCode(applyDataVO.getCode());
            rowDatas.setOperation(applyDataVO.getOperate());
            rowDatas.setStatus(applyDataVO.getStatus());
            rowDatas.setRowIndex(rowIndex[0] + "");
            List<ProppertyVO> proppertyVOList = applyDataVO.getProp();
            LinkedHashMap<Integer, String> integerValueMap = new LinkedHashMap<>();
            Map<String, String> filedValueMap = new HashMap<>();
            if (!CollectionUtils.isEmpty(proppertyVOList)) {
               Map<String, String> sourceKeyValueMap = proppertyVOList.stream().collect(Collectors.toMap(ProppertyVO::getKey, ProppertyVO::getValue, (key1, key2) -> key2));
               Map<String, String> keyValueMap = new HashMap<>();
               //判断attrMapConfigMap是否有值,如果没有则说明基础默认的是编码系统字段
               if (!CollectionUtils.isEmpty(attrMapConfigMap)) {
                  sourceKeyValueMap.keySet().forEach(sourceKey -> {
                     String dataValue = sourceKeyValueMap.get(sourceKey);
                     if (attrMapConfigMap.containsKey(sourceKey)) {
                        String targetKey = attrMapConfigMap.get(sourceKey);
                        log.info("xxxxx属性映射值:sourceKey【"+sourceKey+"】——》+targetKey---》"+targetKey+":"+dataValue);
                        keyValueMap.put(targetKey, StringUtils.isBlank(dataValue)?"":dataValue);
                     }
                  });
               } else {
                  sourceKeyValueMap.forEach((filed,value)->{
                     keyValueMap.put(filed,StringUtils.isBlank(value)?"":value) ;
                  });
               }
               filedIndexMap.forEach((attrKey, column) -> {
                  String keyValue = "";
                  if (keyValueMap.containsKey(attrKey)) {
                     keyValue =StringUtils.isBlank(keyValueMap.get(attrKey))?"":keyValueMap.get(attrKey);
                  }
                  integerValueMap.put(column, keyValue);
                  filedValueMap.put(attrKey, keyValue);
               });
            }
            rowDatas.setData(integerValueMap);
            rowDatas.setFiledValue(filedValueMap);
            rowDataList.add(rowDatas);
         });
         dataObjectVO.setRowData(rowDataList);
      }catch (Throwable e){
         objerrorCode="1";
         e.printStackTrace();
         log.error("组织数据映射值失败",e);
         throw new   Throwable("组织数据映射值失败"+e);
      }
   }
   /*private void codeValueList(List<CodeBasicSecVO> secVOList,String codeseclengthfield ){
      if(StringUtils.isNotBlank(codeseclengthfield)) {
         String[] secLengths = codeseclengthfield.split("#");
         for (int i = 0; i < secLengths.length; i++) {
            CodeBasicSecVO secVO = secVOList.get(i);
            String thisSecValue = "";
               *//*if(i == 0){
                  thisSecValue = seclenghStr.contains("#")?code.substring(0,VciBaseUtil.getInt(secLengths[i])):code;
               } else if(i == secLengths.length-1){
                  //最后
                  thisSecValue =  seclenghStr.contains("#")?code.substring(VciBaseUtil.getInt(secLengths[i-1]),code.length()):code;
               }else {*//*
            int start = 0;
            for (int j = 0; j < i; j++) {
               start += VciBaseUtil.getInt(secLengths[j]);
            }
            thisSecValue = code.substring(start, start + VciBaseUtil.getInt(secLengths[i]));
            //   }
            if (VciBaseUtil.getBoolean(secVO.getSerialDependFlag())) {
               serialUnitList.add(thisSecValue);
               serialSecOidIndexMap.put(secVO.getOid(), i);
            }
            if (CODE_SERIAL_SEC.getValue().equalsIgnoreCase(secVO.getSecType())) {
               serialValueMap.put(secVO.getOid(), thisSecValue);
            }
            codeValueList.add(thisSecValue);
         }
      }else{
      }
   }*/
   /***
    * æ ¡éªŒæ˜¯å¦åšäº†é…ç½®
    * @param systemId,系统标识
    * @param type:接口类型
    * @param operationType:接口操作类型
    * @return
    */
   private DockingSystemConfig  checkIspass(String systemId,String type,String operationType,String classOid){
      log.info("systemId:"+systemId+",type:"+SysIntegrationDataFlowTypeEnum.getTextByValue(type)+",operationType:"+sysIntegrationPushTypeEnum.getTextByValue(operationType)+",classOid:"+classOid);
      //CodeClassifyVO codeClassifyVO= classifyService.getObjectByOid(classOid);
      List<CodeClassify> codeClassifyList=  classifyService.selectAllLevelParentByOid(classOid);
      List<String> classifyOids=new ArrayList<>();
      if(!CollectionUtils.isEmpty(codeClassifyList)) {
         classifyOids = codeClassifyList.stream().map(CodeClassify::getOid).collect(Collectors.toList());
      }else{
         return null;
      }
      //classOid=codeClassifyVO.getOid();
      //根据类型去查询需要集成的分类或者数据
      LambdaQueryWrapper<DockingSystemConfig> queryWrapper = Wrappers.<DockingSystemConfig>lambdaQuery();
      queryWrapper.eq(DockingSystemConfig::getUsedFlag, MdmDuckingConstant.SEND_FLAG_TRUE);
      queryWrapper.eq(DockingSystemConfig::getSysBaseId,systemId);
      queryWrapper.eq(DockingSystemConfig::getDataFlowType,type);
      queryWrapper.eq(DockingSystemConfig::getPushType,operationType);
      if(StringUtils.isNotBlank(classOid)){
         queryWrapper.in(DockingSystemConfig::getClassifyOid,classifyOids);
      }
      List<DockingSystemConfig> dockingSystemConfigList=new ArrayList<>();
      dockingSystemConfigList=   dockingSystemConfigList=dockingSystemConfigService.list(queryWrapper);
      if(!CollectionUtils.isEmpty(dockingSystemConfigList)){
         return   dockingSystemConfigList.get(0);
      }else{
         return null;
      }
   }
   /***
    * è®°å½•日志信息
    * @param systemId
    * @param parmaData
    * @param result
    * @return
    */
   private  void saveLogs(String systemId,String systemName,String parmaData, String result,boolean isSucess,String msg,String operation){
      //记录日志信息
      DockingLog dockingLoge=new DockingLog();
      //String oid=redisService.getUUIDEveryDay();
      dockingLoge.setSystemCode(StringUtils.isBlank(systemId)?"-":systemId);//设置系统标识
      dockingLoge.setSystemName(StringUtils.isBlank(systemName)?"-":systemName);
      dockingLoge.setMsg(msg);//日志消息
      dockingLoge.setClassifyId("-");//分类编号
      dockingLoge.setClassifyName("-");//分类名称
      dockingLoge.setClassifyOid("-");//分类主键
      dockingLoge.setUniqueCode("-");//唯一标识
      dockingLoge.setSystemOid("-");//系统标识
//        dockingLogeDO.setName(operation);
      //dockingLogeDO.setOid(oid);//日志主键
      dockingLoge.setParamString(parmaData);//参数信息
      dockingLoge.setReturnString(result);//返回信息
      dockingLoge.setType(operation);//日志操作类型
      dockingLoge.setCreateTime(new Date());
      if(isSucess) {
         dockingLoge.setInterfaceStatus("true");//接口集成状态
      }else{
         dockingLoge.setInterfaceStatus("false");//接口集成状态
      }
      dockingLogeService.save(dockingLoge);
      log.info("集成推送数据,systemId:"+systemId+",systemname:"+systemName+",operation:"+operation+",param:"+parmaData);
   }
   /***
    * å±žæ€§ç±»åž‹è½¬æ¢
    * @param vaule
    * @return
    */
   private  String objectToStr(Object vaule) {
      String newValue="";
      if(vaule ==null||"".equals(vaule)||vaule==""){
         return "";
      }
      try {
         if (vaule instanceof Integer) {
            Integer intValue = (Integer) vaule;
            newValue = String.valueOf(intValue);
         } else if (vaule instanceof Boolean) {
            boolean boolValue = (Boolean) vaule;
            newValue = Boolean.toString(boolValue);
         } else if (vaule instanceof Timestamp) {
            Timestamp timestampValue = (Timestamp) vaule;
            newValue = timestamp2Str(timestampValue);
         } else if (vaule instanceof Date) {
            Date dataValue = (Date) vaule;
            newValue = date2Str(dataValue, "yyyy-MM-dd HH:mm:ss");
         }else if (vaule instanceof BigDecimal){
            BigDecimal bigDecimal=(BigDecimal)vaule;
            newValue =  bigDecimal.toString();
         } else {
            return vaule.toString();
         }
      }catch (Throwable e){
         //   log.error("属性类型转换错误",e);
         e.printStackTrace();
      }
      return newValue;
   }
   private String date2Str(Date date, String format) {
      if (null == date) {
         return null;
      } else {
         if (format == null || format.trim().length() == 0) {
            format = "yyyy-MM-dd HH:mm:ss.SSS";
         }
         SimpleDateFormat sdf = new SimpleDateFormat(format);
         return sdf.format(date);
      }
   }
   private  String timestamp2Str(Timestamp time) {
      Date date = null;
      if (null == time) {
         return null;
      } else {
         if (null != time) {
            date = new Date(time.getTime());
         }
         return date2Str(date, "yyyy-MM-dd HH:mm:ss.SSS");
      }
   }
}