ludc
2024-03-22 96f493d717f7238e956c3e870ba5437cb6cf4ae4
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
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 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编码资源管理系统,被其他集成的系统的通用接口调用示例
 * @author ludc
 * @date 2024/2/27 20:34
 */
@Service
@AllArgsConstructor
public class CalledIntegrationServiceImpl implements ICalledIntegrationService {
 
    /**
     * 统一申请接口URL
     */
    private final String UNIAPPLYURL = "http://localhost:37000/ubcs-code/applyCode";
 
    /**
     * 标准申请接口URL
     */
    private final String UNIAPPLYBZURL = "http://localhost:37000/ubcs-code/applyCodeBZ";
 
    private final UniversalInterface universalInterface;
 
    /**
     * 对编码系统的统一申请接口调用,rest方式
     */
    @Override
    public void sendApplyCodeByRest() {
        // 组织数据
        MultiValueMap<String, String> params = new LinkedMultiValueMap<>();
        params.add("dataType","json");
        //params.add("dataType","xml");根据需求自行选择
        params.add("dataString","");//根据需求自行组织json格式或者xml格式的数据
        // 是xml时的格式示例:
        /*<?xml version="1.0" encoding="UTF-8" standalone="no"?>
            <data systemId="PDM">
            <user ip="localhost" trueName="pwdfree" userName="pwdfree"/>
            <classifys>
            <classify classCode="1045" fullclsfNamePath="" library="10">
            <sections>
            <section name="分类" value="1045"/>
            </sections>
            <objects>
            <object code="" creator="pwdfree" id="MP.100001" operate="create" status="Released">
            <prop key="partclassification" text="分类" value="1045"/>
            <prop key="c6e_partClass" text="Part分类" value="毛坯"/>
            <prop key="c6e_drawingNo" text="图号" value="1000021"/>
            <prop key="c6e_material" text="材料牌号" value="XXX"/>
            <prop key="c6e_blankStandard" text="毛坯标准" value="G235"/>
            <prop key="c6e_materialStandard" text="技术标准" value="AAAA"/>
            </object>
            </objects>
            </classify>
            </classifys>
            </data>
         */
        // 是json时的格式示例
        params.add(
                "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\" } } } "
        );
        MultiValueMap<String, String> headers = new LinkedMultiValueMap<>();
        String res = HttpUtils.post(UNIAPPLYURL,params,headers);
    }
 
    /**
     * 对编码系统统一申请接口调用,WebService方式
     */
    @Override
    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);
    }
 
    /**
     * 对标准申码接口调用示例: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);
 
    }
 
 
}