xiejun
2024-01-25 e581891072a36f0d0f7f57246366ded965e2ab8a
Source/UBCS/ubcs-service/ubcs-code/src/main/java/com/vci/ubcs/code/service/impl/CodeDuckingSyncServiceImpl.java
@@ -7,8 +7,10 @@
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.thoughtworks.xstream.XStream;
import com.thoughtworks.xstream.io.xml.DomDriver;
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.dto.datapush.classify.JsonRootDataDTO;
import com.vci.ubcs.code.dto.datapush.classify.NodeClassifyDTO;
import com.vci.ubcs.code.dto.datapush.classify.NodeDataDTO;
@@ -22,6 +24,7 @@
import com.vci.ubcs.code.dto.datapush.result.ResultNodeObjectDTO;
import com.vci.ubcs.code.entity.*;
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.feign.MdmSearchItemCodeProvider;
import com.vci.ubcs.code.mapper.CommonsMapper;
@@ -31,6 +34,7 @@
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.ProppertyVO;
import com.vci.ubcs.code.vo.webserviceModel.apply.SectionVO;
import com.vci.ubcs.code.vo.webserviceModel.applybz.ApplyBZDataVO;
import com.vci.ubcs.code.vo.webserviceModel.applybz.ApplyBZDatasVO;
import com.vci.ubcs.code.vo.webserviceModel.attrmap.*;
@@ -70,12 +74,14 @@
import javax.servlet.http.HttpServletRequest;
import javax.xml.ws.WebServiceContext;
import javax.xml.ws.handler.MessageContext;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.concurrent.atomic.AtomicReference;
import java.util.stream.Collectors;
import static com.vci.ubcs.code.constant.MdmDuckingConstant.*;
import static com.vci.ubcs.code.constant.MdmEngineConstant.DEFAULT_SYNC_ATTR_LIST;
import static com.vci.ubcs.code.enumpack.CodeSecTypeEnum.CODE_CLASSIFY_SEC;
/*
@@ -129,6 +135,8 @@
   @Resource
   private ICodeClassifyService codeClassifyService;
   @Autowired
   private ICodeClassifyValueService codeClassifyValueService;
   @Autowired(required = false)
   private AttributeMapConfig attributeMapConfig;
   /***
@@ -213,10 +221,18 @@
   @Override
   public void saveItemDataSyncScheduing(String btmName) {
      SearchItemParam searchItemParam=new SearchItemParam();
      searchItemParam.setSystag("CODE"); //调用系统标识
      searchItemParam.setLastchangedon(new Date());
      searchItemParam.setSystag("VCI"); //调用系统标识
      Calendar calendar= Calendar.getInstance();
      calendar.set(Calendar.HOUR_OF_DAY,0);
      calendar.set(Calendar.MINUTE,0);
      calendar.set(Calendar.SECOND,0);
      log.info("查询时间------->"+calendar.getTime());
      SimpleDateFormat dft = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
      String lastchangedon= dft.format(calendar.getTime());
      searchItemParam.setLastchangedon(lastchangedon);
      searchItemParam.setStatus("1");//
      SearchItemVO searchItemVO= mdmSearchItemCodeProvider.getppModelByElem(searchItemParam);
      Map<String,String>searchDataMap=  VciBaseUtil.objectToMapString(searchItemParam);
      SearchItemVO searchItemVO= mdmSearchItemCodeProvider.getppModelByElem(searchDataMap);
      if(searchItemVO!=null) {
         try {
            //免密登录申请token,request中添加用户信息
@@ -265,7 +281,8 @@
               sb.append(tableName);
               sb.append(" where 1=1");
               sb.append(" and lastr=1 and lastv=1");
               sb.append(" and codeclsfid = '" + codeClassify.getOid() + "'");
               sb.append(" and codeclsfid = '" + codeClassify.getOid() + "' ");
               sb.append( VciBaseUtil.toInSql(attrKey,VciBaseUtil.array2String(itemCodeList.toArray(new String[]{}))));
               List<Map<String, String>> newDataList = commonsMapper.queryByOnlySqlForMap(sb.toString());
               //List<BaseModel> baseModelList=new ArrayList<>();
               Map<String,BaseModel> baseModelMap=new HashMap<>();
@@ -278,7 +295,6 @@
                  baseModelMap.put(attrKeyValue,baseModel);
               });
               ApplyDatasVO editDatasVO = new ApplyDatasVO();
               List<ApplyDataVO> addObjectList=new ArrayList<>();
               List<ApplyDataVO> editObjectList=new ArrayList<>();
               dataVOMap.forEach((key,value)->{
@@ -290,6 +306,16 @@
                  }
               });
               if(!CollectionUtils.isEmpty(addObjectList)){
                  //规则的主键需要去获取
                  CodeClassifyFullInfoBO classifyFullInfo = codeClassifyService.getClassifyFullInfo(codeClassify.getOid());
                  if(classifyFullInfo==null ||classifyFullInfo.getCurrentClassifyVO()==null || StringUtils.isBlank(classifyFullInfo.getCurrentClassifyVO().getOid())){
                     log.info("classifyFullInfo:"+"根据传输的分类,未获取分类相关信息");
                     throw  new  Throwable ("根据传输的分类,未获取分类相关信息");
                  }
                  CodeRuleVO ruleVO = mdmEngineServiceI.getCodeRuleByClassifyFullInfo(classifyFullInfo);
                  if(ruleVO==null||StringUtils.isBlank(ruleVO.getOid())){
                     throw  new  Throwable ("根据传输的分类,未获取MDM系统中对应规则");
                  }
                  DataObjectVO dataObjectVO = new DataObjectVO();
                  ApplyDatasVO applyDatasVO = new ApplyDatasVO();
                  applyDatasVO.setObject(addObjectList);
@@ -297,23 +323,25 @@
                  this.getConfigDatas(systemId, btmName, applyDatasVO, attrVOS, dataObjectVO);
                  CodeOrderDTO orderDTO = new CodeOrderDTO();
                  orderDTO.setCodeClassifyOid(codeClassify.getOid());//分类主键
                  log.info("end:规则获取完毕");
                  List<CodeOrderSecDTO> codeOrderSecDTOList = getRuleCodeOrderSecDTOs(null, ruleVO,classifyFullInfo);
                  log.info("end:码段获取完毕");
                  orderDTO.setSecDTOList(codeOrderSecDTOList);//分类码段
                  mdmIOService.batchSyncApplyCode(orderDTO, applyDatasVO, resultDataObjectDetailDOs,false);
                  mdmIOService.batchSyncApplyCode(orderDTO, dataObjectVO, resultDataObjectDetailDOs,false);
               }
               if(!CollectionUtils.isEmpty(editObjectList)){
                  DataObjectVO dataObjectVO = new DataObjectVO();
                  ApplyDatasVO applyDatasVO = new ApplyDatasVO();
                  LinkedList<XMLResultDataObjectDetailDO> resultDataObjectDetailDOs = new LinkedList<>();
                  CodeClassifyVO codeClassifyVO=new CodeClassifyVO();
                  BeanUtilForVCI.copyPropertiesIgnoreCase(codeClassify, codeClassifyVO);                  this.getConfigDatas(systemId, btmName, applyDatasVO, attrVOS, dataObjectVO);
                  BeanUtilForVCI.copyPropertiesIgnoreCase(codeClassify, codeClassifyVO);
                  this.getConfigDatas(systemId, btmName, applyDatasVO, attrVOS, dataObjectVO);
                  mdmIOService.batchSyncEditDatas(codeClassifyVO,dataObjectVO, resultDataObjectDetailDOs,false);
               }
            }
         }
         catch (Throwable e){
@@ -321,7 +349,67 @@
         }
      }
   }
   /***
    * 根据传入的参数信息校验码段规则
    */
   private List<CodeOrderSecDTO> getRuleCodeOrderSecDTOs(List<SectionVO> SectionVOList, CodeRuleVO ruleVO, CodeClassifyFullInfoBO classifyFullInfo) throws Throwable{
      List<CodeBasicSecVO>  codeBasicSecVOS= ruleVO.getSecVOList();
      Map<String,String> sectionVOMap=new HashMap<>();
      SectionVOList.stream().forEach(SectionVO->{
         sectionVOMap.put(SectionVO.getName(),SectionVO.getValue());
      });
      //Map<String,CodeClassifyVO> codeClassifyVOMap= classifyFullInfo.getParentClassifyVOs().stream().collect(Collectors.toMap(s -> s.getId(), t -> t,(o1, o2)->o2));
      List<CodeOrderSecDTO> codeOrderSecDTOList=new ArrayList<>();
      Map<String,String> errorMap=new HashMap<>();
      for(CodeBasicSecVO codeBasicSecVO: codeBasicSecVOS) {
         String sectype = codeBasicSecVO.getSecType();
         String newSecName=codeBasicSecVO.getName();
         String classifySecOid= codeBasicSecVO.getOid();
         String message="";
         if (!sectype.equals(CodeSecTypeEnum.CODE_SERIAL_SEC.getValue())) {
            String name = codeBasicSecVO.getName();
            String sectypeText = codeBasicSecVO.getSecTypeText();
            log.info("码段名称:"+name);
            log.info("描述:"+sectypeText);
            CodeOrderSecDTO CodeOrderSecDTO = new CodeOrderSecDTO();
            if (sectionVOMap.containsKey(name)) {
               CodeOrderSecDTO.setSecOid(codeBasicSecVO.getOid());
               String sectypeValue = sectionVOMap.get(name);
               log.info("码段值:"+sectypeValue);
               CodeSecTypeEnum secType = CodeSecTypeEnum.forValue(sectype);
               if(CODE_CLASSIFY_SEC.equals(secType)) {//如果是分类的话,则需要匹配传过来的分类代号与
                  //先简称是否有关联模板,有模板要先删除
                  List<CodeClassifyValue> codeClassifyValueDOList = codeClassifyValueService.list(Wrappers.<CodeClassifyValue>query().lambda().eq(CodeClassifyValue::getCodeClassifySecOid,classifySecOid));
                  if (!CollectionUtils.isEmpty(codeClassifyValueDOList)) {
                     Map<String, CodeClassifyValue> codeClassifyValueDOMap = codeClassifyValueDOList.stream().collect(Collectors.toMap(s -> s.getId(), t -> t, (o1, o2) -> o2));
                     if(codeClassifyValueDOMap.containsKey(sectypeValue)){
                        CodeClassifyValue codeClassifyValue=   codeClassifyValueDOMap.get(sectypeValue);
                        sectypeValue=codeClassifyValue.getOid();
                     }else {
                        //throw new Throwable("传入的分类码段:【" + name + " 值:" + sectypeValue + "】,不符合当前分类层级代号");
                        message="传入的分类码段:【" + name + " 值:" + sectypeValue + "】,不符合当前分类层级代号";
                        errorMap.put("error",errorMap.getOrDefault("error","")+";"+message);
                     }
                  }
               }
               if(StringUtils.isBlank(sectypeValue)){
                  message="传入的分类码段:【" + name + " 】的值不允许为空";
                  errorMap.put("error",errorMap.getOrDefault("error","")+";"+message);
               }
               CodeOrderSecDTO.setSecValue(sectypeValue);
               codeOrderSecDTOList.add(CodeOrderSecDTO);
            } else {
               message="传入的码段规则缺少" + name;
               errorMap.put("error",errorMap.getOrDefault("error","")+";"+message);
            }
         }
      }
      if(errorMap.size()>0){
         throw new Throwable(errorMap.getOrDefault("error",""));
      }
      return codeOrderSecDTOList;
   }
   /***
    * 读取属性映射配置信息
    * @param systemId
@@ -331,7 +419,8 @@
    * @param dataObjectVO
    * @throws Throwable
    */
   public void getConfigDatas(String systemId, String libray, ApplyBZDatasVO applyDatasVO, List<CodeClassifyTemplateAttrVO> codeClassifyTemplateAttrVOList, DataObjectVO dataObjectVO) throws Throwable {
   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<>();
@@ -374,6 +463,11 @@
      //根据分类模板组织数据
      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();
@@ -383,21 +477,21 @@
         dataObjectVO.setColName(rowNameList);//放入属性
         attrMapConfigMap.putAll(propMaps);
         LinkedList<RowDatas> rowDataList = new LinkedList<>();
         List<ApplyBZDataVO> applyBZDataVOList=new ArrayList<>();
         List<ApplyDataVO> applyDataVOList=new ArrayList<>();
         if(!CollectionUtils.isEmpty(applyDatasVO.getObject())){
            applyBZDataVOList=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};
         applyBZDataVOList.stream().forEach(applyDataVO -> {
         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("create");
            rowDatas.setOperation(applyDataVO.getOperate());
            rowDatas.setStatus(applyDataVO.getStatus());
            rowDatas.setRowIndex(rowIndex[0] + "");
            List<ProppertyVO> proppertyVOList = applyDataVO.getProp();
@@ -405,7 +499,7 @@
            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> sourceKeyValueMap = proppertyVOList.stream().collect(Collectors.toMap(ProppertyVO::getKey, ProppertyVO::getValue, (key1, key2) -> key2));
               Map<String, String> keyValueMap = new HashMap<>();
               //判断attrMapConfigMap是否有值,如果没有则说明基础默认的是编码系统字段
               if (!CollectionUtils.isEmpty(attrMapConfigMap)) {