xiejun
2023-08-25 f6de710d9492cc165211becc7d9e7c27f5724012
Source/UBCS/ubcs-service/ubcs-code/src/main/java/com/vci/ubcs/code/service/impl/UniversalInterfaceImpl.java
@@ -6,6 +6,7 @@
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.thoughtworks.xstream.XStream;
import com.thoughtworks.xstream.io.xml.DomDriver;
import com.vci.ubcs.code.applyjtcodeservice.feign.IMdmInterJtClient;
import com.vci.ubcs.code.bo.CodeClassifyFullInfoBO;
import com.vci.ubcs.code.constant.MdmDuckingConstant;
import com.vci.ubcs.code.dto.CodeOrderDTO;
@@ -58,7 +59,8 @@
import javax.annotation.Resource;
import java.util.*;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.atomic.AtomicInteger;
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.DEFAULT_SYNC_ATTR_LIST;
@@ -128,6 +130,9 @@
   @Autowired
   private ICodeClassifyValueService codeClassifyValueService;
   @Resource
   private IMdmInterJtClient mdmInterJtClient;
   /***
    * 集成接口日志服务的配置
    */
@@ -149,7 +154,7 @@
   @Override
   public String applyCode(String data, String dataType) throws Throwable {
      String resultStr = "";
      String errorid="0";
      final String[] errorid = {"0"};
      msg="成功";
      objerrorCode="0";
      objerrorMsg="成功";
@@ -159,7 +164,7 @@
      List<XMLResultClassfyVO> resultClassfyVOList = new ArrayList<>();
      try {
         if(StringUtils.isBlank(data)) {
            errorid="101";
            errorid[0] ="101";
            throw new Throwable("接口参数:传递为空");
         }
         InterParameterVO interParameterVO  =new InterParameterVO();
@@ -175,17 +180,11 @@
               interParameterVO = JSONObject.toJavaObject(JSONObject.parseObject(data), InterParameterVO.class);
            }
         }catch (Throwable e){
            errorid="101";
            errorid[0] ="101";
            throw new Throwable("接口参数:传入数据参数解析失败");
         }
         ClassfysVO classfysVO = interParameterVO.getData().getClassifys();
         systemId = interParameterVO.getData().getSystemId();
         //校验是否配置
         boolean checkPass= checkIspass(systemId, SysIntegrationDataFlowTypeEnum.ACCEPT.getValue(), sysIntegrationPushTypeEnum.ACCPET_APPCODE.getValue());
         if(!checkPass){
            errorid="101";
            throw new Throwable("系统标识为【"+systemId+"】,"+sysIntegrationPushTypeEnum.ACCPET_APPCODE.getText()+"接口配置已停用或者未配置,请联系编码管理员!");
         }
         UserVO userVo = interParameterVO.getData().getUser();
         List<ClassfyVO> classVOList = classfysVO.getClassify();
         InterParameterVO finalInterParameterVO = interParameterVO;
@@ -196,20 +195,32 @@
         sessionInfo.setUserName(userVo.getTrueName());
         sessionInfo.setIp(userVo.getIp());
         VciBaseUtil.setCurrentUserSessionInfo(sessionInfo);
//         List<XMLResultDataObjectDetailDO> allResultDataObjectDetailDOS=new ArrayList<>();
         String finalSystemId = systemId;
         classVOList.stream().forEach(classVO -> {
            log.info("参数:分类COde:" + classVO.getClassCode());
            boolean isCodeOrGroupCode=false;
            LinkedList<XMLResultDataObjectDetailDO> resultDataObjectDetailDOs = new LinkedList<>();
            String libray ="";
            //获取分类信息
            try {
               String libray = classVO.getLibrary();
               CodeClassifyVO codeClassifyVO = getClassfy(classVO);
               libray = classVO.getLibrary();
               CodeClassifyVO codeClassifyVO = getClassfy(classVO,libray);
               log.info("end:分类查询完毕");
               //获取分类模板信息
               if(codeClassifyVO==null || StringUtils.isBlank(codeClassifyVO.getOid())){
                  objerrorCode="100";
                  throw  new  Throwable ("根据传输的分类,未获取到分类信息");
               }
               String operation="";
               if(CODE_CHECKCONFIG) {
                  //校验是否配置
                  DockingSystemConfig dockingSystemConfig= checkIspass(finalSystemId, SysIntegrationDataFlowTypeEnum.ACCEPT.getValue(), sysIntegrationPushTypeEnum.ACCPET_APPCODE.getValue(),codeClassifyVO.getOid());
                  if(dockingSystemConfig==null){
                     errorid[0] ="101";
                     throw new Throwable("系统标识为【"+ finalSystemId +"】,集成分类为【"+codeClassifyVO.getName()+"】以上分类,"+sysIntegrationPushTypeEnum.ACCPET_APPCODE.getText()+"接口配置已停用或者未配置,请联系编码管理员!");
                  }
                  isCodeOrGroupCode="true".equals(dockingSystemConfig.getIsGroupCodeFlag())?true:false;
               }
               CodeClassifyTemplateVO templateVO = engineService.getUsedTemplateByClassifyOid(codeClassifyVO.getOid());
               if(templateVO==null||StringUtils.isBlank(templateVO.getOid())){
@@ -241,15 +252,29 @@
               CodeOrderDTO orderDTO = new CodeOrderDTO();
               orderDTO.setCodeClassifyOid(codeClassifyVO.getOid());//分类主键
               orderDTO.setSecDTOList(codeOrderSecDTOList);//分类码段
               mdmIOService.batchSyncApplyCode(orderDTO, dataObjectVO, resultDataObjectDetailDOs);
               mdmIOService.batchSyncApplyCode(orderDTO, dataObjectVO, resultDataObjectDetailDOs,isCodeOrGroupCode);
               //allResultDataObjectDetailDOS.add(resultDataObjectDetailDOs);
               log.info("end:申请获取完毕");
            } catch (Throwable e) {
               XMLResultDataObjectDetailDO xmlResultDataObjectDetailDO=new XMLResultDataObjectDetailDO();
               xmlResultDataObjectDetailDO.setCode("");
               xmlResultDataObjectDetailDO.setId("");
               xmlResultDataObjectDetailDO.setErrorid(objerrorCode);
               xmlResultDataObjectDetailDO.setMsg("编码申请失败:"+e.getMessage());
               resultDataObjectDetailDOs.add(xmlResultDataObjectDetailDO);
               List<ApplyDataVO> applyDataVOList= classVO.getObjects().getObject();
               if(!CollectionUtils.isEmpty(applyDataVOList)) {
                  applyDataVOList.stream().forEach(applyDataVO -> {
                     XMLResultDataObjectDetailDO xmlResultDataObjectDetailDO = new XMLResultDataObjectDetailDO();
                     xmlResultDataObjectDetailDO.setCode("");
                     xmlResultDataObjectDetailDO.setId(applyDataVO.getId());
                     xmlResultDataObjectDetailDO.setErrorid(objerrorCode);
                     xmlResultDataObjectDetailDO.setMsg("编码申请失败:" + e.getMessage());
                     resultDataObjectDetailDOs.add(xmlResultDataObjectDetailDO);
                  });
               }else{
                  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();
@@ -259,14 +284,22 @@
               resultClassfyVO.setObjects(resultDataObjectDetailDOs);
               resultClassfyVOList.add(resultClassfyVO);
            }
            //是否调用集团接口申请接口
            if(isCodeOrGroupCode){
                List<String> IdList=resultDataObjectDetailDOs.stream().filter(xMLResultDataObjectDetailDO->StringUtils.isNotBlank(xMLResultDataObjectDetailDO.getId())).map(XMLResultDataObjectDetailDO::getId).distinct().collect(Collectors.toList());
                if(!CollectionUtils.isEmpty(IdList)) {
                  this.sendApplyGroupcode(IdList, libray,sysIntegrationPushTypeEnum.ACCPET_APPCODE.getValue());
               }
            }
         });
         XMLResultSystemVO xmlResultSystemVO=new XMLResultSystemVO();
         xmlResultSystemVO.setClassifys(resultClassfyVOList);
         xmlResultSystemVO.setMsg(msg);
         xmlResultSystemVO.setErrorid(errorid);
         xmlResultSystemVO.setErrorid(errorid[0]);
         resultStr= transferResultXMl(xmlResultSystemVO,dataType);
      }catch (Throwable e){
         e.printStackTrace();;
         e.printStackTrace();
         msg="申请编码失败:"+e.getMessage();
          /*  XMLResultSystemVO XMLResultSystemVO=new XMLResultSystemVO();
            XMLResultSystemVO.setErrorid(errorid);
@@ -280,10 +313,10 @@
         XMLResultSystemVO xmlResultSystemVO=new XMLResultSystemVO();
         xmlResultSystemVO.setClassifys(resultClassfyVOList);
         xmlResultSystemVO.setMsg(msg);
         xmlResultSystemVO.setErrorid(errorid);
         xmlResultSystemVO.setErrorid(errorid[0]);
         resultStr= transferResultXMl(xmlResultSystemVO,dataType);
         final boolean[] issucess = {true};
         if(!errorid.equals("0")) {
         if(!errorid[0].equals("0")) {
            issucess[0] = false;
         }else {
            if(!CollectionUtils.isEmpty(resultClassfyVOList)) {
@@ -306,10 +339,23 @@
         }
      }
      log.info("返回参数:"+resultStr);
      //调用集团申请接口申请集团码
      return resultStr;
   }
   /***
    * 申请集团编码
    * @param idList
    * @param btmName
    */
   private void sendApplyGroupcode(List<String> idList,String btmName,String operationType){
      String oids=VciBaseUtil.array2String(idList.toArray(new String[]{}));
      if(operationType.equals(sysIntegrationPushTypeEnum.ACCPET_APPCODE.getValue())) {
         mdmInterJtClient.applyGroupCode(oids,btmName);
      }else if(operationType.equals(sysIntegrationPushTypeEnum.ACCPET_EDITCODE)){
         mdmInterJtClient.receiveEditApply(oids,btmName);
      }
   }
   /***
    * 统一更新接口(更改状态,更改属性信息)接口
    * @param data
@@ -376,7 +422,7 @@
            //获取分类信息
            try {
               String libray = classVO.getLibrary();
               CodeClassifyVO codeClassifyVO = getClassfy(classVO);
               CodeClassifyVO codeClassifyVO = getClassfy(classVO,libray);
               if(codeClassifyVO==null || StringUtils.isBlank(codeClassifyVO.getOid())){
                  objerrorCode="100";
                  throw  new  Throwable ("根据传输的分类,未获取到分类信息");
@@ -1282,7 +1328,7 @@
    * 查询校验分类信息
    * @param classfyVO
    */
   private  CodeClassifyVO getClassfy(ClassfyVO classfyVO) throws Throwable{
   private  CodeClassifyVO getClassfy(ClassfyVO classfyVO,String libray) throws Throwable{
      CodeClassifyVO classifyVO = new CodeClassifyVO();
      try {
         String classCode = classfyVO.getClassCode();
@@ -1291,13 +1337,19 @@
         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)) {
               CodeClassify classifyDO = codeClassifyList.get(0);
               //将DTO转换为DO
               codeClassifyList.stream().forEach(codeClassify -> {
                  CodeClassifyVO codeClassifyVO=  classifyService.getTopClassifyVO(codeClassify.getOid());
                  if(codeClassifyVO.getId().equals(libray)){
                     newCodeClassify[0] =codeClassify;
                  }
               });
               classifyVO = new CodeClassifyVO();
               BeanUtilForVCI.copyPropertiesIgnoreCase(classifyDO, classifyVO);
               BeanUtilForVCI.copyPropertiesIgnoreCase(newCodeClassify[0], classifyVO);
               //将DTO转换为DO
               if(StringUtils.isBlank(classifyVO.getOid())){
                  throw new  Throwable("根据分类代号未查询到相应的分类信息");
                  throw new  Throwable("申请编码的分类:【"+classCode+"】不属于库节点【"+libray+"】,请检查参数分类节点/库节点信息是否匹配");
               }
            }else{
               throw new  Throwable("根据分类代号未查询到相应的分类信息");
@@ -1310,7 +1362,7 @@
         }
      }catch (Throwable e){
         objerrorCode="100";
         new  Throwable("获取分类信息失败:"+e.getMessage());
         throw    new  Throwable("获取分类信息失败:"+e.getMessage());
      }
      return classifyVO;
   }
@@ -1598,4 +1650,35 @@
      queryWrapper.eq(DockingSystemConfig::getPushType,operationType);
      return dockingSystemConfigService.count(queryWrapper)>0?true:false;
   }
   /***
    * 校验是否做了配置
    * @param systemId,系统标识
    * @param type:接口类型
    * @param operationType:接口操作类型
    * @return
    */
   private DockingSystemConfig  checkIspass(String systemId,String type,String operationType,String classOid){
      DockingSystemConfig dockingSystemConfig=new DockingSystemConfig();
      CodeClassifyVO codeClassifyVO= classifyService.getObjectByOid(classOid);
      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::getClassifyId,classOid);
      }
      List<DockingSystemConfig> dockingSystemConfigList=   dockingSystemConfigList=dockingSystemConfigService.list(queryWrapper);
      if(!CollectionUtils.isEmpty(dockingSystemConfigList)){
         dockingSystemConfig=dockingSystemConfigList.get(0);
      }else{
         if(StringUtils.isNotBlank(codeClassifyVO.getParentCodeClassifyOid())) {
            checkIspass(systemId, type, operationType, codeClassifyVO.getOid());
         }
      }
      return dockingSystemConfig;
   }
}