田源
2024-05-25 ba345976f0a6a67bcb20627e33251ded000a3d8f
Source/ExampleIntegratedPushCalled/src/main/java/com/vci/ubcs/example/service/impl/CalledIntegrationServiceImpl.java
@@ -1,12 +1,22 @@
package com.vci.ubcs.example.service.impl;
import com.alibaba.fastjson.JSON;
import com.thoughtworks.xstream.XStream;
import com.thoughtworks.xstream.io.xml.DomDriver;
import com.vci.ubcs.example.apply.*;
import com.vci.ubcs.example.applybz.*;
import com.vci.ubcs.example.service.ICalledIntegrationService;
import com.vci.ubcs.example.service.UniversalInterface;
import com.vci.ubcs.example.util.HttpUtils;
import com.vci.ubcs.example.util.WsClientUtil;
import org.springframework.http.MediaType;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import java.net.MalformedURLException;
import java.rmi.RemoteException;
import java.util.ArrayList;
import java.util.List;
/**
 * 统一申请接口:UBCS编码资源管理系统,被其他集成的系统的通用接口调用示例
@@ -14,17 +24,20 @@
 * @date 2024/2/27 20:34
 */
@Service
@AllArgsConstructor
public class CalledIntegrationServiceImpl implements ICalledIntegrationService {
    /**
     * 统一申请接口URL
     */
    private String UNIAPPLYURL = "http://localhost/ubcs-code/applyCode";
    private final String UNIAPPLYURL = "http://localhost:37000/ubcs-code/applyCode";
    /**
     * 标准申请接口URL
     */
    private String UNIAPPLYBZURL = "http://localhost/ubcs-code/applyCodeBZ";
    private final String UNIAPPLYBZURL = "http://localhost:37000/ubcs-code/applyCodeBZ";
    private final UniversalInterface universalInterface;
    /**
     * 对编码系统的统一申请接口调用,rest方式
@@ -72,12 +85,364 @@
     * 对编码系统统一申请接口调用,WebService方式
     */
    @Override
    public void sendApplyCodeByWebService() {
    public void sendApplyCodeByWebService() throws MalformedURLException, RemoteException {
        //使用sopui生成调用webservice接口的代码
        String dataType = "json"; //或者xml
        //String dataString = "\"data\": {\"classifys\": {\"classify\": [{\"classCode\": \"1025\",\"fullclsfNamePath\": \"\",\"library\": \"10\",\"sections\": {\"section\": [{\"name\": \"分类号\",\"value\": \"1025\"},{\"name\": \"顺序号\",\"value\": \"\"}]},\"obejects\": {\"obeject\": [{\"code\": \"\",\"id\": \"\",\"status\": \"Released\",\"operate\": \"create\",\"creator\": \"0000\",\"prop\": [{\"key\": \"name\",\"text\": \"名称\",\"value\": \"\"}]}]}}],\"systemId\": \"ERP\",\"user\": {\"ip\": \"127.0.0.1\",\"trueName\": \"00000\",\"userName\": \"test\"}}}";
        // 请求的主要参数组建
        InterParameterVO interParameterVO = new InterParameterVO();
        RootDataVO rootDataVO = new RootDataVO();
        ClassfysVO classfysVO = new ClassfysVO();
        List<ClassfyVO> classfyVOList = new ArrayList<>();
        ClassfyVO classfyVO = new ClassfyVO();
        classfyVO.setLibrary("10");
        classfyVO.setClassCode("1025");
        ApplyDatasVO applyDatasVO = new ApplyDatasVO();
        List<ApplyDataVO> applyDataVOList = new ArrayList<>();
        ApplyDataVO applyDataVO = new ApplyDataVO();
        applyDataVO.setCode("");
        applyDataVO.setCreator("0000");
        applyDataVO.setEditor("0000");
        applyDataVO.setId("");
        applyDataVO.setOperate("create");
        applyDataVO.setStatus("Released");
        ArrayList<ProppertyVO> proppertyVOS = new ArrayList<>();
        ProppertyVO proppertyVO = new ProppertyVO();
        proppertyVO.setKey("name");
        proppertyVO.setText("名称");
        proppertyVO.setValue("");
        proppertyVOS.add(proppertyVO);
        applyDataVO.setProp(proppertyVOS);
        applyDataVOList.add(applyDataVO);
        applyDatasVO.setObject(applyDataVOList);
        classfyVO.setObjects(applyDatasVO);
        SectionsVO sectionsVO = new SectionsVO();
        List<SectionVO> sectionVOList = new ArrayList<>();
        sectionVOList.add(new SectionVO("分类号","1025"));
        sectionVOList.add(new SectionVO("顺序号","1025"));
        sectionsVO.setSection(sectionVOList);
        classfyVO.setSections(sectionsVO);
        classfysVO.setClassify(classfyVOList);
        rootDataVO.setClassifys(classfysVO);
        UserVO userVO = new UserVO();
        userVO.setIp("127.0.0.1");
        userVO.setTrueName("19861111");
        userVO.setUserName("19861111");
        rootDataVO.setUser(userVO);
        rootDataVO.setSystemId("PDM");
        interParameterVO.setData(rootDataVO);
        // 如果是xml请自行构建xml格式,并将dataType改为xml
        String dataString = JSON.toJSONString(interParameterVO);
        // xml参数形式示例
        XStream xStream = new XStream(new DomDriver());
        String dataString1 = xStream.toXML(interParameterVO);
        String res = universalInterface.applyCode(dataString,dataType);
    }
    /**
     * 对编码系统统一申请接口调用,WebService方式
     */
    @Override
    public void sendApplyCodeByWebServicexml(int frequency) throws MalformedURLException, RemoteException {
        //使用sopui生成调用webservice接口的代码
        String dataType = "xml"; //或者xml
        String dataString = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
                "<data systemId=\"PDM\">\n" +
                "    <user ip=\"130.31.92.101\" trueName=\"王琪\" userName=\"19851584\"/>\n" +
                "    <classifys>\n" +
                "        <classify classCode=\"1025\" fullclsfNamePath=\"\" library=\"10\">\n" +
                "            <sections>\n" +
                "                <section name=\"分类\" value=\"1025\"/>\n" +
                "            </sections>\n" +
                "            <objects>\n" +
                "                <object code=\"\" creator=\"19851584\" id=\"2548M16G02\" operate=\"create\" status=\"Released\">\n" +
                "                    <prop key=\"partclassification\" text=\"分类\" value=\"1025\"/>\n" +
                "                    <prop key=\"c6e_drawingNo\" text=\"图号\" value=\"2548M16G02\"/>\n" +
                "                    <prop key=\"c6e_partClass\" text=\"Part分类\" value=\"设计零组件\"/>\n" +
                "                    <prop key=\"c6e_partName\" text=\"名称\" value=\"高压涡轮静止密封圈\"/>\n" +
                "                    <prop key=\"c6e_hash\" text=\"哈希码\" value=\"/\"/>\n" +
                "                </object>\n" +
                "                <object code=\"\" creator=\"19851584\" id=\"2548M16P06\" operate=\"create\" status=\"Released\">\n" +
                "                    <prop key=\"partclassification\" text=\"分类\" value=\"1025\"/>\n" +
                "                    <prop key=\"c6e_drawingNo\" text=\"图号\" value=\"2548M16P06\"/>\n" +
                "                    <prop key=\"c6e_partClass\" text=\"Part分类\" value=\"设计零组件\"/>\n" +
                "                    <prop key=\"c6e_partName\" text=\"名称\" value=\"法兰盘\"/>\n" +
                "                    <prop key=\"c6e_hash\" text=\"哈希码\" value=\"/\"/>\n" +
                "                </object>\n" +
                "                <object code=\"\" creator=\"19851584\" id=\"2548M16P02\" operate=\"create\" status=\"Released\">\n" +
                "                    <prop key=\"partclassification\" text=\"分类\" value=\"1025\"/>\n" +
                "                    <prop key=\"c6e_drawingNo\" text=\"图号\" value=\"2548M16P02\"/>\n" +
                "                    <prop key=\"c6e_partClass\" text=\"Part分类\" value=\"设计零组件\"/>\n" +
                "                    <prop key=\"c6e_partName\" text=\"名称\" value=\"焊接法兰盘\"/>\n" +
                "                    <prop key=\"c6e_hash\" text=\"哈希码\" value=\"/\"/>\n" +
                "                </object>\n" +
                "                <object code=\"\" creator=\"19851584\" id=\"2548M16P05\" operate=\"create\" status=\"Released\">\n" +
                "                    <prop key=\"partclassification\" text=\"分类\" value=\"1025\"/>\n" +
                "                    <prop key=\"c6e_drawingNo\" text=\"图号\" value=\"2548M16P05\"/>\n" +
                "                    <prop key=\"c6e_partClass\" text=\"Part分类\" value=\"设计零组件\"/>\n" +
                "                    <prop key=\"c6e_partName\" text=\"名称\" value=\"防风罩\"/>\n" +
                "                    <prop key=\"c6e_hash\" text=\"哈希码\" value=\"/\"/>\n" +
                "                </object>\n" +
                "                <object code=\"\" creator=\"19851584\" id=\"2548M16P03\" operate=\"create\" status=\"Released\">\n" +
                "                    <prop key=\"partclassification\" text=\"分类\" value=\"1025\"/>\n" +
                "                    <prop key=\"c6e_drawingNo\" text=\"图号\" value=\"2548M16P03\"/>\n" +
                "                    <prop key=\"c6e_partClass\" text=\"Part分类\" value=\"设计零组件\"/>\n" +
                "                    <prop key=\"c6e_partName\" text=\"名称\" value=\"封严蜂窝\"/>\n" +
                "                    <prop key=\"c6e_hash\" text=\"哈希码\" value=\"/\"/>\n" +
                "                </object>\n" +
                "                <object code=\"\" creator=\"19851584\" id=\"2548M16P04\" operate=\"create\" status=\"Released\">\n" +
                "                    <prop key=\"partclassification\" text=\"分类\" value=\"1025\"/>\n" +
                "                    <prop key=\"c6e_drawingNo\" text=\"图号\" value=\"2548M16P04\"/>\n" +
                "                    <prop key=\"c6e_partClass\" text=\"Part分类\" value=\"设计零组件\"/>\n" +
                "                    <prop key=\"c6e_partName\" text=\"名称\" value=\"蜂窝封严边\"/>\n" +
                "                    <prop key=\"c6e_hash\" text=\"哈希码\" value=\"/\"/>\n" +
                "                </object>\n" +
                "                <object code=\"\" creator=\"19851584\" id=\"2551M46P01\" operate=\"create\" status=\"Released\">\n" +
                "                    <prop key=\"partclassification\" text=\"分类\" value=\"1025\"/>\n" +
                "                    <prop key=\"c6e_drawingNo\" text=\"图号\" value=\"2551M46P01\"/>\n" +
                "                    <prop key=\"c6e_partClass\" text=\"Part分类\" value=\"设计零组件\"/>\n" +
                "                    <prop key=\"c6e_partName\" text=\"名称\" value=\"壳体固定环\"/>\n" +
                "                    <prop key=\"c6e_hash\" text=\"哈希码\" value=\"/\"/>\n" +
                "                </object>\n" +
                "                <object code=\"\" creator=\"19851584\" id=\"2552M51G07\" operate=\"create\" status=\"Released\">\n" +
                "                    <prop key=\"partclassification\" text=\"分类\" value=\"1025\"/>\n" +
                "                    <prop key=\"c6e_drawingNo\" text=\"图号\" value=\"2552M51G07\"/>\n" +
                "                    <prop key=\"c6e_partClass\" text=\"Part分类\" value=\"设计零组件\"/>\n" +
                "                    <prop key=\"c6e_partName\" text=\"名称\" value=\"压气机机匣尾部中心支架\"/>\n" +
                "                    <prop key=\"c6e_hash\" text=\"哈希码\" value=\"/\"/>\n" +
                "                </object>\n" +
                "                <object code=\"\" creator=\"19851584\" id=\"2552M51P08\" operate=\"create\" status=\"Released\">\n" +
                "                    <prop key=\"partclassification\" text=\"分类\" value=\"1025\"/>\n" +
                "                    <prop key=\"c6e_drawingNo\" text=\"图号\" value=\"2552M51P08\"/>\n" +
                "                    <prop key=\"c6e_partClass\" text=\"Part分类\" value=\"设计零组件\"/>\n" +
                "                    <prop key=\"c6e_partName\" text=\"名称\" value=\"压气机机匣尾部中心支架\"/>\n" +
                "                    <prop key=\"c6e_hash\" text=\"哈希码\" value=\"/\"/>\n" +
                "                </object>\n" +
                "                <object code=\"\" creator=\"19851584\" id=\"2552M51P02\" operate=\"create\" status=\"Released\">\n" +
                "                    <prop key=\"partclassification\" text=\"分类\" value=\"1025\"/>\n" +
                "                    <prop key=\"c6e_drawingNo\" text=\"图号\" value=\"2552M51P02\"/>\n" +
                "                    <prop key=\"c6e_partClass\" text=\"Part分类\" value=\"设计零组件\"/>\n" +
                "                    <prop key=\"c6e_partName\" text=\"名称\" value=\"压气机尾部中心支架\"/>\n" +
                "                    <prop key=\"c6e_hash\" text=\"哈希码\" value=\"/\"/>\n" +
                "                </object>\n" +
                "                <object code=\"\" creator=\"19851584\" id=\"4127T52P06\" operate=\"create\" status=\"Released\">\n" +
                "                    <prop key=\"partclassification\" text=\"分类\" value=\"1025\"/>\n" +
                "                    <prop key=\"c6e_drawingNo\" text=\"图号\" value=\"4127T52P06\"/>\n" +
                "                    <prop key=\"c6e_partClass\" text=\"Part分类\" value=\"设计零组件\"/>\n" +
                "                    <prop key=\"c6e_partName\" text=\"名称\" value=\"销子\"/>\n" +
                "                    <prop key=\"c6e_hash\" text=\"哈希码\" value=\"/\"/>\n" +
                "                </object>\n" +
                "            </objects>\n" +
                "        </classify>\n" +
                "        <classify classCode=\"1040\" fullclsfNamePath=\"\" library=\"10\">\n" +
                "            <sections>\n" +
                "                <section name=\"分类\" value=\"1040\"/>\n" +
                "            </sections>\n" +
                "            <objects>\n" +
                "                <object code=\"\" creator=\"19851584\" id=\"LEAP 1B-ZP1\" operate=\"create\" status=\"Released\">\n" +
                "                    <prop key=\"partclassification\" text=\"分类\" value=\"1040\"/>\n" +
                "                    <prop key=\"c6e_drawingNo\" text=\"图号\" value=\"LEAP 1B-ZP1\"/>\n" +
                "                    <prop key=\"c6e_partClass\" text=\"Part分类\" value=\"制造过程件\"/>\n" +
                "                    <prop key=\"c6e_hash\" text=\"哈希码\" value=\"/\"/>\n" +
                "                    <prop key=\"c6e_partName\" text=\"名称\" value=\"LEAP 1B发动机交付件\"/>\n" +
                "                </object>\n" +
                "            </objects>\n" +
                "        </classify>\n" +
                "    </classifys>\n" +
                "</data>";
        for (int i = 0; i <= frequency; i++) {
            String res = universalInterface.applyCode(dataString,dataType);
            System.out.println("第"+i+"次执行,返回结果:"+res);
        }
        System.out.println("=================END=======================");
    }
    /**
     * 对标准申码接口调用示例:rest方式,调用方式和统一申码接口没有区别,只是参数上有所调整
     */
    public void sendApplyCodeBZByRest(){
        // 组织数据
        MultiValueMap<String, String> params = new LinkedMultiValueMap<>();
        params.add("dataType","json");
        //params.add("dataType","xml");根据需求自行选择
        // 是json时的格式示例
        ApplyBZParamVO applyBZParamVO = new ApplyBZParamVO();
        ApplyBZVO applyBZVO = new ApplyBZVO();
        ClassfyBZVO classfyBZVO = new ClassfyBZVO();
        classfyBZVO.setClassCode("BZHWJ");
        classfyBZVO.setLibrary("standard");
        SectionsVO sectionsVO = new SectionsVO();
        List<SectionVO> sectionVOList = new ArrayList<>();
        SectionVO sectionVO = new SectionVO();
        sectionVO.setName("文件分类");
        sectionVO.setValue("BJT");
        sectionVOList.add(sectionVO);
        SectionVO sectionVO1 = new SectionVO();
        sectionVO.setName("文件分类");
        sectionVO.setValue("BJT");
        sectionVOList.add(sectionVO1);
        SectionVO sectionVO2 = new SectionVO();
        sectionVO.setName("分隔符");
        sectionVO.setValue("-");
        sectionVOList.add(sectionVO2);
        SectionVO sectionVO3 = new SectionVO();
        sectionVO.setName("年代号");
        sectionVO.setValue("2024");
        sectionVOList.add(sectionVO3);
        SectionVO sectionVO4 = new SectionVO();
        sectionVO.setName("顺序号");
        sectionVO.setValue("");
        sectionVOList.add(sectionVO3);
        sectionsVO.setSection(sectionVOList);
        classfyBZVO.setSections(sectionsVO);
        ApplyBZDatasVO applyBZDatasVO = new ApplyBZDatasVO();
        ArrayList<ApplyBZDataVO> applyBZDataVOS = new ArrayList<>();
        ApplyBZDataVO applyBZDataVO = new ApplyBZDataVO();
        applyBZDataVO.setCode("");
        // 修订时必传
        applyBZDataVO.setOldCode("");
        applyBZDataVO.setCreator("19822111");
        // 是否修订为系列
        applyBZDataVO.setEditSeriesFlag(false);
        // 是否为系列申请
        applyBZDataVO.setSeriesFlag(false);
        // 发布时间
        applyBZDataVO.setReleaseTime("2024-3-21");
        applyBZDataVO.setId("cassafaf11332213678sdf12673626222");
        // 文档中通常会有描述,1是申码,2是修订
        applyBZDataVO.setOperationType("1");
        applyBZDataVO.setStatus("Released");
        // 年代号
        applyBZDataVO.setYearNumber("2024");
        // 流水号
        applyBZDataVO.setSeriesFlow("");
        List<ProppertyVO> proppertyVOS = new ArrayList<>();
        ProppertyVO proppertyVO = new ProppertyVO();
        proppertyVO.setText("名称");
        proppertyVO.setKey("测试-首件鉴定");
        proppertyVO.setValue("standardName");
        proppertyVOS.add(proppertyVO);
        ProppertyVO proppertyVO1 = new ProppertyVO();
        proppertyVO1.setText("发布日期");
        proppertyVO1.setKey("2024-3-21");
        proppertyVO1.setValue("publishDate");
        proppertyVOS.add(proppertyVO1);
        applyBZDataVO.setProp(proppertyVOS);
        applyBZDatasVO.setObject(applyBZDataVOS);
        classfyBZVO.setObjects(applyBZDatasVO);
        applyBZVO.setClassify(classfyBZVO);
        UserVO userVO = new UserVO();
        userVO.setIp("127.0.0.1");
        userVO.setTrueName("19861111");
        userVO.setUserName("19861111");
        applyBZVO.setUser(userVO);
        applyBZVO.setSystemId("standardization");
        applyBZParamVO.setData(applyBZVO);
        // xml参数形式示例
        XStream xStream = new XStream(new DomDriver());
        String dataString1 = xStream.toXML(applyBZParamVO);
        params.add("dataString",JSON.toJSONString(applyBZParamVO));
        MultiValueMap<String, String> headers = new LinkedMultiValueMap<>();
        String res = HttpUtils.post(UNIAPPLYBZURL,params,headers);
    }
    /**
     * 对标准申码接口调用示例:webservice方式,调用方式和统一申码接口没有区别,只是参数上有所调整
     */
    public void sendApplyCodeBZWebservice() throws RemoteException {
        //使用sopui生成调用webservice接口的代码
        String dataType = "json"; //或者xml
        // 是json时的格式示例
        ApplyBZParamVO applyBZParamVO = new ApplyBZParamVO();
        ApplyBZVO applyBZVO = new ApplyBZVO();
        ClassfyBZVO classfyBZVO = new ClassfyBZVO();
        classfyBZVO.setClassCode("BZHWJ");
        classfyBZVO.setLibrary("standard");
        SectionsVO sectionsVO = new SectionsVO();
        List<SectionVO> sectionVOList = new ArrayList<>();
        sectionsVO.setSection(sectionVOList);
        classfyBZVO.setSections(sectionsVO);
        ApplyBZDatasVO applyBZDatasVO = new ApplyBZDatasVO();
        ArrayList<ApplyBZDataVO> applyBZDataVOS = new ArrayList<>();
        ApplyBZDataVO applyBZDataVO = new ApplyBZDataVO();
        applyBZDataVO.setCode("");
        // 修订时必传
        applyBZDataVO.setOldCode("");
        applyBZDataVO.setCreator("19822111");
        // 是否修订为系列
        applyBZDataVO.setEditSeriesFlag(false);
        // 是否为系列申请
        applyBZDataVO.setSeriesFlag(false);
        // 发布时间
        applyBZDataVO.setReleaseTime("2024-3-21");
        applyBZDataVO.setId("cassafaf11332213678sdf12673626222");
        // 文档中通常会有描述,1是申码,2是修订
        applyBZDataVO.setOperationType("1");
        applyBZDataVO.setStatus("Released");
        // 年代号
        applyBZDataVO.setYearNumber("2024");
        // 流水号
        applyBZDataVO.setSeriesFlow("");
        List<ProppertyVO> proppertyVOS = new ArrayList<>();
        ProppertyVO proppertyVO = new ProppertyVO();
        proppertyVO.setText("名称");
        proppertyVO.setKey("测试-首件鉴定");
        proppertyVO.setValue("standardName");
        proppertyVOS.add(proppertyVO);
        ProppertyVO proppertyVO1 = new ProppertyVO();
        proppertyVO1.setText("发布日期");
        proppertyVO1.setKey("2024-3-21");
        proppertyVO1.setValue("publishDate");
        proppertyVOS.add(proppertyVO1);
        applyBZDataVO.setProp(proppertyVOS);
        applyBZDatasVO.setObject(applyBZDataVOS);
        classfyBZVO.setObjects(applyBZDatasVO);
        applyBZVO.setClassify(classfyBZVO);
        UserVO userVO = new UserVO();
        userVO.setIp("127.0.0.1");
        userVO.setTrueName("19861111");
        userVO.setUserName("19861111");
        applyBZVO.setUser(userVO);
        applyBZVO.setSystemId("standardization");
        applyBZParamVO.setData(applyBZVO);
        // 如果是xml请自行构建xml格式,并将dataType改为xml
        String dataString = JSON.toJSONString(applyBZParamVO);
        // xml参数形式示例
        XStream xStream = new XStream(new DomDriver());
        String dataString1 = xStream.toXML(applyBZParamVO);
        String res = universalInterface.applyCodeForBZ(dataString,dataType);
    }
}