ludc
2023-05-18 6138318ebe15d251d6ae6e3e1ec57c8af94216d7
Source/UBCS/ubcs-service/ubcs-code/src/main/java/com/vci/ubcs/code/service/impl/UniversalInterfaceImpl.java
@@ -2,16 +2,13 @@
import com.alibaba.cloud.commons.lang.StringUtils;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
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.dto.CodeOrderDTO;
import com.vci.ubcs.code.dto.CodeOrderSecDTO;
import com.vci.ubcs.code.entity.CodeBasicSec;
import com.vci.ubcs.code.entity.CodeClassify;
import com.vci.ubcs.code.entity.DockingLog;
import com.vci.ubcs.code.entity.*;
import com.vci.ubcs.code.enumpack.CodeSecTypeEnum;
import com.vci.ubcs.code.service.*;
import com.vci.ubcs.code.util.gennerAttrMapUtil;
@@ -69,8 +66,8 @@
   /**
    * 主数据引擎的服务
    */
   //@Resource
   //private MdmEngineService engineService;
   @Resource
   private MdmEngineService engineService;
   /**
    * 密级的服务
@@ -99,152 +96,152 @@
   @Override
   public String applyCode(String data, String dataType) throws Throwable {
      {
//         String resultStr = "";
//         String errorid="0";
//         msg="成功";
//         objerrorCode="0";
//         objerrorMsg="成功";
//         logger.info("申请编码的数据参数:->"+data);
//         logger.info("申请编码的数据类型:->"+dataType);
//         String systemId="";
//         List<XMLResultClassfyVO> resultClassfyVOList = new ArrayList<>();
//         try {
//            if(StringUtils.isBlank(data)) {
//               errorid="101";
//               throw new Throwable("接口参数:传递为空");
//            }
//            InterParameterVO interParameterVO  =new InterParameterVO();
//            //如果dataType是xml则,通过xml序列化成对象形式,如果是json则通过json转换成对象格式
//            try {
//               if ("xml".equals(dataType)) {
//                  XStream xStream = new XStream(new DomDriver());
//                  xStream.processAnnotations(RootDataVO.class);
//                  xStream.autodetectAnnotations(true);
//                  RootDataVO rootDataVO = (RootDataVO) xStream.fromXML(data);
//                  interParameterVO.setData(rootDataVO);
//               } else {
//                  interParameterVO = JSONObject.toJavaObject(JSONObject.parseObject(data), InterParameterVO.class);
//               }
//            }catch (Throwable e){
//               errorid="101";
//               throw new Throwable("接口参数:传入数据参数解析失败");
//            }
//            ClassfysVO classfysVO = interParameterVO.getData().getClassifys();
//            systemId = interParameterVO.getData().getSystemId();
//            UserVO userVo = interParameterVO.getData().getUser();
//            List<ClassfyVO> classVOList = classfysVO.getClassify();
//            InterParameterVO finalInterParameterVO = interParameterVO;
//
//            //这是账号信息
//            SessionInfo sessionInfo = new SessionInfo();
//            sessionInfo.setUserId(userVo.getUserName());
//            sessionInfo.setUserName(userVo.getTrueName());
//            sessionInfo.setIp(userVo.getIp());
//            VciBaseUtil.setCurrentUserSessionInfo(sessionInfo);
//
//            String finalSystemId = systemId;
//            classVOList.stream().forEach(classVO -> {
//               logger.info("参数:分类COde:" + classVO.getClassCode());
//               LinkedList<XMLResultDataObjectDetailDO> resultDataObjectDetailDOs = new LinkedList<>();
//               //获取分类信息
//               try {
//                  String libray = classVO.getLibrary();
//                  CodeClassifyVO codeClassifyVO = getClassfy(classVO);
//                  logger.info("end:分类查询完毕");
//                  //获取分类模板信息
//                  if(codeClassifyVO==null || StringUtils.isBlank(codeClassifyVO.getOid())){
//                     objerrorCode="100";
//                     throw  new  Throwable ("根据传输的分类,未获取到分类信息");
//                  }
//                  CodeClstemplateVO templateVO = engineService.getUsedTemplateByClassifyOid(codeClassifyVO.getOid());
//                  if(templateVO==null||StringUtils.isBlank(templateVO.getOid())){
//                     objerrorCode="1";
//                     throw  new  Throwable ("根据传输的分类,未获取MDM系统中对应模板");
//                  }
//                  logger.info("end:模板查询完毕");
//                  ApplyDatasVO applyDatasVO = classVO.getObjects();
//                  DataObjectVO dataObjectVO = new DataObjectVO();
//                  List<CodeClassifyTemplateAttrVO> attrVOS = templateVO.getAttributes().stream().filter(s -> !DEFAULT_SYNC_ATTR_LIST.contains(s.getId()) && VciBaseUtil.getBoolean(s.getFormDisplayFlag())
//                  ).collect(Collectors.toList());
//                  this.getConfigDatas(finalSystemId, libray, applyDatasVO, attrVOS, dataObjectVO);
//                  logger.info("end:数据组织完毕");
//                  //规则的主键需要去获取
//                  CodeClassifyFullInfoBO classifyFullInfo = classifyService.getClassifyFullInfo(codeClassifyVO.getOid());
//                  if(classifyFullInfo==null ||classifyFullInfo.getCurrentClassifyVO()==null || StringUtils.isBlank(classifyFullInfo.getCurrentClassifyVO().getOid())){
//                     objerrorCode="1";
//                     logger.info("classifyFullInfo:"+"根据传输的分类,未获取分类相关信息");
//                     throw  new  Throwable ("根据传输的分类,未获取分类相关信息");
//                  }
//                  CodeRuleVO ruleVO = engineService.getCodeRuleByClassifyFullInfo(classifyFullInfo);
//                  if(ruleVO==null|| StringUtils.isBlank(ruleVO.getOid())){
//                     objerrorCode="102";
//                     throw  new  Throwable ("根据传输的分类,未获取MDM系统中对应规则");
//                  }
//                  logger.info("end:规则获取完毕");
//                  List<CodeOrderSecDTO> codeOrderSecDTOList = getRuleCodeOrderSecDTOs(classVO.getSections().getSection(), ruleVO);
//                  logger.info("end:码段获取完毕");
//                  CodeOrderDTO orderDTO = new CodeOrderDTO();
//                  orderDTO.setCodeClassifyOid(codeClassifyVO.getOid());//分类主键
//                  orderDTO.setSecDTOList(codeOrderSecDTOList);//分类码段
//                  mdmIOService.batchSyncApplyCode(orderDTO, dataObjectVO, resultDataObjectDetailDOs);
//                  logger.info("end:申请获取完毕");
//               } catch (Throwable e) {
//                  XMLResultDataObjectDetailDO xmlResultDataObjectDetailDO=new XMLResultDataObjectDetailDO();
//                  xmlResultDataObjectDetailDO.setCode("");
//                  xmlResultDataObjectDetailDO.setId("");
//                  xmlResultDataObjectDetailDO.setErrorid(objerrorCode);
//                  xmlResultDataObjectDetailDO.setMsg("编码申请失败:"+e.getMessage());
//                  resultDataObjectDetailDOs.add(xmlResultDataObjectDetailDO);
//                  e.printStackTrace();
//               }finally {
//                  XMLResultClassfyVO resultClassfyVO = new XMLResultClassfyVO();
//                  resultClassfyVO.setClassCode(classVO.getClassCode());
//                  resultClassfyVO.setLibrary(classVO.getLibrary());
//                  resultClassfyVO.setFullclsfNamePath(classVO.getFullclsfNamePath());
//                  resultClassfyVO.setObjects(resultDataObjectDetailDOs);
//                  resultClassfyVOList.add(resultClassfyVO);
//               }
//            });
//            XMLResultSystemVO xmlResultSystemVO=new XMLResultSystemVO();
//            xmlResultSystemVO.setClassifys(resultClassfyVOList);
//            xmlResultSystemVO.setMsg(msg);
//            xmlResultSystemVO.setErrorid(errorid);
//            resultStr= transferResultXMl(xmlResultSystemVO,dataType);
//         }catch (Throwable e){
//            e.printStackTrace();;
//            msg="申请编码失败:"+e.getMessage();
//         }finally {
//            XMLResultSystemVO xmlResultSystemVO=new XMLResultSystemVO();
//            xmlResultSystemVO.setClassifys(resultClassfyVOList);
//            xmlResultSystemVO.setMsg(msg);
//            xmlResultSystemVO.setErrorid(errorid);
//            resultStr= transferResultXMl(xmlResultSystemVO,dataType);
//            final boolean[] issucess = {true};
//            if(!errorid.equals("0")) {
//               issucess[0] = false;
//            }else {
//               if(!CollectionUtils.isEmpty(resultClassfyVOList)) {
//                  resultClassfyVOList.stream().forEach(xMLResultClassfyVO -> {
//                     xMLResultClassfyVO.getObjects().stream().forEach(objec -> {
//                        if (!(objec.getErrorid().equals("0") || objec.getErrorid().equals("204"))) {
//                           issucess[0] = false;
//                           msg=objec.getMsg();
//                        }
//                     });
//                  });
//               }
//
//            }
//            try {
//               //记录日志
//               this.saveLogs(systemId, systemId, data, resultStr, issucess[0], msg, "applyCode");
//            }catch (Throwable e){
//               e.printStackTrace();
//            }
//         }
//         logger.info("返回参数:"+resultStr);
         String resultStr = "";
         String errorid="0";
         msg="成功";
         objerrorCode="0";
         objerrorMsg="成功";
         logger.info("申请编码的数据参数:->"+data);
         logger.info("申请编码的数据类型:->"+dataType);
         String systemId="";
         List<XMLResultClassfyVO> resultClassfyVOList = new ArrayList<>();
         try {
            if(StringUtils.isBlank(data)) {
               errorid="101";
               throw new Throwable("接口参数:传递为空");
            }
            InterParameterVO interParameterVO  =new InterParameterVO();
            //如果dataType是xml则,通过xml序列化成对象形式,如果是json则通过json转换成对象格式
            try {
               if ("xml".equals(dataType)) {
                  XStream xStream = new XStream(new DomDriver());
                  xStream.processAnnotations(RootDataVO.class);
                  xStream.autodetectAnnotations(true);
                  RootDataVO rootDataVO = (RootDataVO) xStream.fromXML(data);
                  interParameterVO.setData(rootDataVO);
               } else {
                  interParameterVO = JSONObject.toJavaObject(JSONObject.parseObject(data), InterParameterVO.class);
               }
            }catch (Throwable e){
               errorid="101";
               throw new Throwable("接口参数:传入数据参数解析失败");
            }
            ClassfysVO classfysVO = interParameterVO.getData().getClassifys();
            systemId = interParameterVO.getData().getSystemId();
            UserVO userVo = interParameterVO.getData().getUser();
            List<ClassfyVO> classVOList = classfysVO.getClassify();
            InterParameterVO finalInterParameterVO = interParameterVO;
         return "";
            //这是账号信息
            SessionInfo sessionInfo = new SessionInfo();
            sessionInfo.setUserId(userVo.getUserName());
            sessionInfo.setUserName(userVo.getTrueName());
            sessionInfo.setIp(userVo.getIp());
            VciBaseUtil.setCurrentUserSessionInfo(sessionInfo);
            String finalSystemId = systemId;
            classVOList.stream().forEach(classVO -> {
               logger.info("参数:分类COde:" + classVO.getClassCode());
               LinkedList<XMLResultDataObjectDetailDO> resultDataObjectDetailDOs = new LinkedList<>();
               //获取分类信息
               try {
                  String libray = classVO.getLibrary();
                  CodeClassifyVO codeClassifyVO = getClassfy(classVO);
                  logger.info("end:分类查询完毕");
                  //获取分类模板信息
                  if(codeClassifyVO==null || StringUtils.isBlank(codeClassifyVO.getOid())){
                     objerrorCode="100";
                     throw  new  Throwable ("根据传输的分类,未获取到分类信息");
                  }
                  CodeClassifyTemplateVO templateVO = engineService.getUsedTemplateByClassifyOid(codeClassifyVO.getOid());
                  if(templateVO==null||StringUtils.isBlank(templateVO.getOid())){
                     objerrorCode="1";
                     throw  new  Throwable ("根据传输的分类,未获取MDM系统中对应模板");
                  }
                  logger.info("end:模板查询完毕");
                  ApplyDatasVO applyDatasVO = classVO.getObjects();
                  DataObjectVO dataObjectVO = new DataObjectVO();
                  List<CodeClassifyTemplateAttrVO> attrVOS = templateVO.getAttributes().stream().filter(s -> !DEFAULT_SYNC_ATTR_LIST.contains(s.getId()) && VciBaseUtil.getBoolean(s.getFormDisplayFlag())
                  ).collect(Collectors.toList());
                  this.getConfigDatas(finalSystemId, libray, applyDatasVO, attrVOS, dataObjectVO);
                  logger.info("end:数据组织完毕");
                  //规则的主键需要去获取
                  CodeClassifyFullInfoBO classifyFullInfo = classifyService.getClassifyFullInfo(codeClassifyVO.getOid());
                  if(classifyFullInfo==null ||classifyFullInfo.getCurrentClassifyVO()==null || StringUtils.isBlank(classifyFullInfo.getCurrentClassifyVO().getOid())){
                     objerrorCode="1";
                     logger.info("classifyFullInfo:"+"根据传输的分类,未获取分类相关信息");
                     throw  new  Throwable ("根据传输的分类,未获取分类相关信息");
                  }
                  CodeRuleVO ruleVO = engineService.getCodeRuleByClassifyFullInfo(classifyFullInfo);
                  if(ruleVO==null|| StringUtils.isBlank(ruleVO.getOid())){
                     objerrorCode="102";
                     throw  new  Throwable ("根据传输的分类,未获取MDM系统中对应规则");
                  }
                  logger.info("end:规则获取完毕");
                  List<CodeOrderSecDTO> codeOrderSecDTOList = getRuleCodeOrderSecDTOs(classVO.getSections().getSection(), ruleVO);
                  logger.info("end:码段获取完毕");
                  CodeOrderDTO orderDTO = new CodeOrderDTO();
                  orderDTO.setCodeClassifyOid(codeClassifyVO.getOid());//分类主键
                  orderDTO.setSecDTOList(codeOrderSecDTOList);//分类码段
                  //mdmIOService.batchSyncApplyCode(orderDTO, dataObjectVO, resultDataObjectDetailDOs);
                  logger.info("end:申请获取完毕");
               } catch (Throwable e) {
                  XMLResultDataObjectDetailDO xmlResultDataObjectDetailDO=new XMLResultDataObjectDetailDO();
                  xmlResultDataObjectDetailDO.setCode("");
                  xmlResultDataObjectDetailDO.setId("");
                  xmlResultDataObjectDetailDO.setErrorid(objerrorCode);
                  xmlResultDataObjectDetailDO.setMsg("编码申请失败:"+e.getMessage());
                  resultDataObjectDetailDOs.add(xmlResultDataObjectDetailDO);
                  e.printStackTrace();
               }finally {
                  XMLResultClassfyVO resultClassfyVO = new XMLResultClassfyVO();
                  resultClassfyVO.setClassCode(classVO.getClassCode());
                  resultClassfyVO.setLibrary(classVO.getLibrary());
                  resultClassfyVO.setFullclsfNamePath(classVO.getFullclsfNamePath());
                  resultClassfyVO.setObjects(resultDataObjectDetailDOs);
                  resultClassfyVOList.add(resultClassfyVO);
               }
            });
            XMLResultSystemVO xmlResultSystemVO=new XMLResultSystemVO();
            xmlResultSystemVO.setClassifys(resultClassfyVOList);
            xmlResultSystemVO.setMsg(msg);
            xmlResultSystemVO.setErrorid(errorid);
            resultStr= transferResultXMl(xmlResultSystemVO,dataType);
         }catch (Throwable e){
            e.printStackTrace();;
            msg="申请编码失败:"+e.getMessage();
         }finally {
            XMLResultSystemVO xmlResultSystemVO=new XMLResultSystemVO();
            xmlResultSystemVO.setClassifys(resultClassfyVOList);
            xmlResultSystemVO.setMsg(msg);
            xmlResultSystemVO.setErrorid(errorid);
            resultStr= transferResultXMl(xmlResultSystemVO,dataType);
            final boolean[] issucess = {true};
            if(!errorid.equals("0")) {
               issucess[0] = false;
            }else {
               if(!CollectionUtils.isEmpty(resultClassfyVOList)) {
                  resultClassfyVOList.stream().forEach(xMLResultClassfyVO -> {
                     xMLResultClassfyVO.getObjects().stream().forEach(objec -> {
                        if (!(objec.getErrorid().equals("0") || objec.getErrorid().equals("204"))) {
                           issucess[0] = false;
                           msg=objec.getMsg();
                        }
                     });
                  });
               }
            }
            try {
               //记录日志
               this.saveLogs(systemId, systemId, data, resultStr, issucess[0], msg, "applyCode");
            }catch (Throwable e){
               e.printStackTrace();
            }
         }
         logger.info("返回参数:"+resultStr);
         return resultStr;
      }
   }
@@ -315,10 +312,10 @@
               throw new  Throwable("根据分类代号未查询到相应的分类信息");
            }
         } else {
            //classifyVO = classifyService.getObjectByClsfNamePath(className.replace(separator, "/"));
            //if(StringUtils.isBlank(classifyVO.getOid())){
            //   throw new  Throwable("根据分类名称路径未查询到相应的分类信息");
            //}
            classifyVO = classifyService.getObjectByClsfNamePath(className.replace(separator, "/"));
            if(StringUtils.isBlank(classifyVO.getOid())){
               throw new  Throwable("根据分类名称路径未查询到相应的分类信息");
            }
         }
      }catch (Throwable e){
         objerrorCode="100";