2
13693261870
2022-09-16 653761a31dfeb50dd3d007e892d69c90bf0cdafc
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
package com.landtool.lanbase.modules.res.controller;
 
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
 
import javax.wsdl.WSDLException;
import javax.xml.parsers.ParserConfigurationException;
 
import org.apache.axis.utils.XMLUtils;
import org.apache.shiro.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;
import org.xml.sax.SAXException;
 
import com.landtool.lanbase.common.annotation.LogAction;
import com.landtool.lanbase.common.utils.WAWsdlUtil;
import com.landtool.lanbase.config.SysTemPropertyConfig;
import com.landtool.lanbase.modules.org.entity.OrgUnit;
import com.landtool.lanbase.modules.org.entity.OrgUser;
import com.landtool.lanbase.modules.org.service.OrgUserService;
import com.landtool.lanbase.modules.res.entity.Res_ExtInterFaceService;
import com.landtool.lanbase.modules.res.entity.Res_MainInfo;
import com.landtool.lanbase.modules.res.service.ResExtInterFaceService;
import com.landtool.lanbase.modules.res.service.ResMainInfoService;
import com.landtool.lanbase.modules.sys.controller.AbstractController;
 
@Controller
@RequestMapping("/res")
public class ResExtInterFaceServiceController extends AbstractController {
    @Autowired
    private ResExtInterFaceService resExtInterFaceService;
 
    @Autowired
    private ResMainInfoService resMainInfoService;
 
    @Autowired
    private OrgUserService orgUserService;
 
 
    @Autowired
    private SysTemPropertyConfig sysConfig;
 
    /**
     * 访问资源接口服务拓展信息页面
     * @param resMainInfoId
     * @param model
     * @return
     */
    @RequestMapping("/ResManage/ResRegister/ExtInterFaceService")
    public String ExtInterFaceService(int resMainInfoId, Model model) {
        Res_ExtInterFaceService res_extInterFaceService = resExtInterFaceService.selectByPrimaryKey(resMainInfoId);//获取接口服务拓展信息
        if (res_extInterFaceService != null) {
            model.addAttribute("Res_ExtInterFaceService", res_extInterFaceService);
            Res_MainInfo res_mainInfo = resMainInfoService.selectByPrimaryKey(resMainInfoId);
            model.addAttribute("resMainInfo", res_mainInfo);
        } else {
            res_extInterFaceService = new Res_ExtInterFaceService();
            model.addAttribute("Res_ExtInterFaceService", res_extInterFaceService);
            model.addAttribute("resMainInfo", new Res_MainInfo());
        }
        model.addAttribute("resMainInfoId", resMainInfoId);
        model.addAttribute("content", res_extInterFaceService.getHelpurl());
 
        if(SecurityUtils.getSubject().isPermitted("org_user_admin")) {
            //判断当前用户是否是管理员,是管理员或是未提交的资源才可以修改资源相关信息
            model.addAttribute("admin",true);
        }
        else {
            model.addAttribute("admin",false);
        }
        model.addAttribute("esbWebServiceHost",sysConfig.getEsbWebServiceHost());
        model.addAttribute("esbHost",sysConfig.getEsbHost());
        model.addAttribute("esbUrl",sysConfig.getEsbUrl());
        return "ResManage/ResRegister/ExtInterFaceService";
    }
 
    @ResponseBody
    @RequestMapping("/ResManage/ResRegister/serverurl")
    public String serverurl(int resMainInfoId, Model model)  {
        Res_ExtInterFaceService res_extInterFaceService = resExtInterFaceService.selectByPrimaryKey(resMainInfoId);//获取接口服务拓展信息
        if (res_extInterFaceService != null ) {
            if(!res_extInterFaceService.getServerurl().equals("")){
                Long userId = getUserId();  //获取用户ID
                OrgUnit orgUnit = getUnit();//获取用户单位信息
                Map<String, Object> map = new HashMap<>();
                map.put("resourceid", resMainInfoId);
                map.put("userid", userId);
                OrgUser user = getUser();
                map.put("unitid", orgUserService.getDefaultUnit(user.getUserid()).getUnitid() );
                int count = resMainInfoService.checkZiYuanQuanXian(map);
                if(count>0){
                    return "{'serverurl':'"+res_extInterFaceService.getServerurl()+"' }";
                }else {
                    return "0";
                }
 
            }else {
                return null;
            }
        }else {
            return null;
        }
    }
 
 
    /**
     * 根据ID删除系统资源拓展信息功能
     */
    @ResponseBody
    @RequestMapping("/resExtInterFaceService/deleteByPrimaryKey")
    public int deleteByPrimaryKey(int resourceid) {
        return resExtInterFaceService.deleteByPrimaryKey(resourceid);
    }
 
    /**
     * 插入系统资源拓展信息功能并且增加更新功能
     */
    @ResponseBody
    @RequestMapping("/resExtInterFaceService/insertSelectiveAndUpdate")
    @LogAction("资源管理,资源发布,资源修改,修改|zy")
    public int insertSelectiveAndUpdate(Res_ExtInterFaceService entity,Res_MainInfo mainInfo) {
        Res_ExtInterFaceService res_extInterFaceService = resExtInterFaceService.selectByPrimaryKey(entity.getResourceid());
        int result = 0;
        int interFaceResult = 0;
        if (res_extInterFaceService == null) {
            interFaceResult = resExtInterFaceService.insertSelective(entity);//添加
        } else {
            interFaceResult = resExtInterFaceService.updateByPrimaryKeySelective(entity);//更新
        }
        if(interFaceResult == 1){
            result = resMainInfoService.updateByPrimaryKeySelective(mainInfo);
        }
        return result;
    }
 
    @RequestMapping("/resExtInterFaceService/WSDL")
    public String WSDL(Model model,int resMainInfoId) throws WSDLException {
        Res_ExtInterFaceService res_extInterFaceService = resExtInterFaceService.selectByPrimaryKey(resMainInfoId);//获取接口服务拓展信息
        if (!res_extInterFaceService.getServerurl().equals("")) {
            String wsdluri = res_extInterFaceService.getServerurl()+"?wsdl";
            List<String> operations = new ArrayList<String>();
            List<Object> list=new ArrayList<>();
            try {
                WAWsdlUtil.getOperationList(wsdluri, operations);
                for (String operationName : operations) {
                    String Json = wsdlJX(operationName,wsdluri);
                    list.add(Json);
                }
            }catch (WSDLException e){
                e.setLocation("地址错了");
                System.out.println(e);
            }
            model.addAttribute("pubzyWebRoot", sysConfig.getPubzyWebRoot());
            model.addAttribute("webUrl",res_extInterFaceService.getServerurl()+"?op=");
            model.addAttribute("Obj", list);
 
        } else {
            model.addAttribute("pubzyWebRoot", sysConfig.getPubzyWebRoot());
//            model.addAttribute("Obj", list);
        }
 
 
        return "ResManage/ResRegister/WSDL";
    }
 
    public String wsdlJX(String functionName,String url) {
        InputStream is = null;
        Document document = null;
        StringBuilder data = new StringBuilder();
        data.append("{");
        String request = "";
        String request1 = "";
        data.append("functionName:'"+functionName+"',");
        int b = 0;
        try {
            document = XMLUtils.newDocument(url);
//            document = XMLUtils.newDocument("http://18.1.2.13:9090/gpsdateconversion/DateConversion.asmx?op=DOYToDate");
            Element elem = document.getDocumentElement();
            NodeList list = elem.getElementsByTagName("wsdl:portType");
            Element Element1 = (Element) list.item(0);
            NodeList wsdlOperationList = Element1.getElementsByTagName("wsdl:operation");
            for (int i = 0; i < wsdlOperationList.getLength(); i++) {
                Element wsdlOperation = (Element) wsdlOperationList.item(i);
                if (wsdlOperation.getAttribute("name").equals(functionName)) {
                    request = ((Element) wsdlOperation.getElementsByTagName("wsdl:documentation").item(0)).getFirstChild().getNodeValue();
                    data.append("ShuoMing:'"+request+"',");
                    break;
                }
            }
            data.append("ChanShus:[");
            NodeList list2 = elem.getElementsByTagName("wsdl:types");
            Element Element2 = (Element) list2.item(0);
            NodeList list3 = Element2.getElementsByTagName("s:schema");
            Element Element3 = (Element) list3.item(0);
            NodeList wsdlOperationList2 = Element3.getElementsByTagName("s:element");
            for (int i = 0; i < wsdlOperationList2.getLength(); i++) {
                Element wsdlOperation1 = (Element) wsdlOperationList2.item(i);
                if (wsdlOperation1.getAttribute("name").equals(functionName)) {
                    NodeList CanShuList =  wsdlOperation1.getElementsByTagName("s:element");
                    for (int j=0;j<CanShuList.getLength();j++){
                        Element Canshu = (Element) CanShuList.item(j);
                        data.append("{");
                        String C1=Canshu.getAttribute("name");
                        String C2=Canshu.getAttribute("type");
                        data.append("name:'"+C1+"',"+"type:'"+C2+"'},");
                    }
                    data.deleteCharAt(data.length()-1);
                    data.append("],");
                    break;
                }
            }
            for (int i = 0; i < wsdlOperationList2.getLength(); i++) {
                Element wsdlOperation1 = (Element) wsdlOperationList2.item(i);
                if (wsdlOperation1.getAttribute("name").equals(functionName+"Response")) {
                    NodeList CanShuList =  wsdlOperation1.getElementsByTagName("s:element");
                    for (int j=0;j<CanShuList.getLength();j++){
                        Element Canshu = (Element) CanShuList.item(j);
                        request1=Canshu.getAttribute("type");
                        data.append("ResultType:'"+request1+"'");
                    }
                    data.append("}");
                    break;
                }
            }
        }
        catch (SAXException e) {
            e.printStackTrace();
        } catch (ParserConfigurationException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return data.toString();
    }
 
    /**
     * 检查上下文地址是否唯一
     */
    @ResponseBody
    @RequestMapping("/resExtInterFaceService/isExistContextPath")
    public int isExistContextPath(Res_ExtInterFaceService record) {
        int result = resExtInterFaceService.isExistContextPath(record.getContextpath());
        return result;
    }
}