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
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
package com.landtool.lanbase.modules.res.controller;
 
import static com.landtool.lanbase.common.utils.HttpOperateUtils.httpGet;
 
import java.io.IOException;
import java.util.Map;
 
import org.apache.commons.lang.StringEscapeUtils;
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 com.alibaba.fastjson.JSONObject;
import com.landtool.lanbase.common.annotation.LogAction;
import com.landtool.lanbase.common.utils.HttpOperateUtils;
import com.landtool.lanbase.modules.res.entity.Res_ExtIntegrate;
import com.landtool.lanbase.modules.res.entity.Res_ExtMapUrl;
import com.landtool.lanbase.modules.res.entity.Res_MainInfo;
import com.landtool.lanbase.modules.res.service.ResExtIntegrateService;
import com.landtool.lanbase.modules.res.service.ResExtMapUrlService;
import com.landtool.lanbase.modules.res.service.ResMainInfoService;
 
/**
 * @Author: lizhao
 * @Description:10系统资源扩展(业务集成)(RES_EXTINTEGRATE)
 *
 */
@Controller
@RequestMapping("/res")
public class ResExtIntegrateController {
    @Autowired
    private ResExtIntegrateService resExtIntegrateService;
 
    @Autowired
    private ResMainInfoService resMainInfoService;
 
    @Autowired
    private ResExtMapUrlService resExtMapUrlService;
 
    /**
     * 访问资源业务集成图层信息页面
     */
    @RequestMapping("/ResManage/ResRegister/ExtIntegrate")
    public String ExtIntegrate(int resMainInfoId, Model model) {
        Res_ExtIntegrate resExtIntegrate = resExtIntegrateService.selectByPrimaryKey(resMainInfoId);
        Integer isSetChart = 0;//是否显示模型设置按钮(0不显示1显示)
        String serverUrl = "";
        String resolutionBen = "";
        String resolutionEnd = "";
        if (resExtIntegrate != null) {
            model.addAttribute("Res_ExtIntegrate", resExtIntegrate);
            model.addAttribute("resMainInfoId", resMainInfoId);
            //获取关联基础底图资源名称
            if(resExtIntegrate.getRefbasemapid() != null) {
                Res_MainInfo res_mainInfo1 = resMainInfoService.selectByPrimaryKey(resExtIntegrate.getRefbasemapid());
                String name = res_mainInfo1.getTitle();
                model.addAttribute("baseMapLayerName",name);
            }
            //获取关联业务图层资源名称
            if(resExtIntegrate.getReflayerid() != null) {
                Res_MainInfo res_mainInfo = resMainInfoService.selectByPrimaryKey(resExtIntegrate.getReflayerid());
                String name = res_mainInfo.getTitle();
                model.addAttribute("reflayername",name);
            }
            Res_MainInfo res_mainInfo = resMainInfoService.selectByPrimaryKey(resMainInfoId);
            model.addAttribute("resMainInfo",res_mainInfo);
            if(resExtIntegrate.getRendermode() != null && resExtIntegrate.getRendermode().equals("统计图")){
                isSetChart = 1;
            }
            serverUrl = resExtIntegrate.getServerurl();
            if(resExtIntegrate.getResolution() != null && resExtIntegrate.getResolution().length() != 0){
                String resolution = resExtIntegrate.getResolution();
                resolutionBen = resolution.substring(0,resolution.indexOf("X"));
                resolutionEnd = resolution.substring(resolution.indexOf("X")+1,resolution.length());
            }
        } else {
            Res_ExtIntegrate resExtIntegrate1 = new Res_ExtIntegrate();
            model.addAttribute("Res_ExtIntegrate", resExtIntegrate1);
            model.addAttribute("resMainInfo",new Res_MainInfo());
        }
        model.addAttribute("isSetChart", isSetChart);
        model.addAttribute("serverUrl", serverUrl);
        model.addAttribute("resolutionBen", resolutionBen);
        model.addAttribute("resolutionEnd", resolutionEnd);
 
        if(SecurityUtils.getSubject().isPermitted("org_user_admin")) {
            //判断当前用户是否是管理员,是管理员或是未提交的资源才可以修改资源相关信息
            model.addAttribute("admin",true);
        }
        else {
            model.addAttribute("admin",false);
        }
        return "ResManage/ResRegister/ExtIntegrate";
    }
 
    /** 根据id 删除系统资源扩展列表功能*/
    @ResponseBody
    @RequestMapping("/resExtIntegrate/deleteByPrimaryKey")
    public int deleteByPrimaryKey(int resourceid) {
        return resExtIntegrateService.deleteByPrimaryKey(resourceid);
    }
 
    @ResponseBody
    @RequestMapping("/resExtIntegrate/insert")
    public int insert(Res_ExtIntegrate record) {
        return resExtIntegrateService.insert(record);
    }
 
    /**
     * 新增或更新
     * @param record
     * @return
     */
    @ResponseBody
    @RequestMapping("/resExtIntegrate/insertSelectiveAndUpdate")
    @LogAction("资源管理,资源发布,资源修改,修改|zy")
    public int insertSelectiveAndUpdate(Res_ExtIntegrate record) {
        Res_ExtIntegrate resExtIntegrate=resExtIntegrateService.selectByPrimaryKey(record.getResourceid());
        if(record.getServerurl() != null && record.getServerurl().length() > 0){
            record.setServerurl(StringEscapeUtils.unescapeHtml(record.getServerurl()));
        }
        if(resExtIntegrate==null){
            //添加
            if(record.getIntegratetype().equals("页面集成")) {
                String showmodel = record.getShowmodel();
                int id = record.getResourceid();
                String url = record.getServerurl();
                String type = record.getIntegratetype();
                Res_ExtIntegrate res_extIntegrate = new Res_ExtIntegrate();
                res_extIntegrate.setResourceid(id);
                res_extIntegrate.setIntegratetype(type);
                res_extIntegrate.setServerurl(url);
                res_extIntegrate.setShowmodel(showmodel);
                res_extIntegrate.setResolution(record.getResolution());
                return resExtIntegrateService.insertSelective(res_extIntegrate);
            }
            if(record.getIntegratetype().equals("数据集成")) {
                if (record.getShowmodel() != null) {
                    record.setShowmodel(null);
                    record.setResolution(null);
                }
                return resExtIntegrateService.insertSelective(record);
            }
        }else {
            //更新
            if(record.getIntegratetype().equals("页面集成")) {
                String showmodel = record.getShowmodel();
                int id = record.getResourceid();
                String url = record.getServerurl();
                String type = record.getIntegratetype();
                Res_ExtIntegrate res_extIntegrate = new Res_ExtIntegrate();
                res_extIntegrate.setResourceid(id);
                res_extIntegrate.setIntegratetype(type);
                res_extIntegrate.setServerurl(url);
                res_extIntegrate.setShowmodel(showmodel);
                res_extIntegrate.setResolution(record.getResolution());
                return resExtIntegrateService.updateByPrimaryKeyWithBLOBs(res_extIntegrate);
            }
            if(record.getIntegratetype().equals("数据集成")) {
                if (resExtIntegrate.getShowmodel() != null) {  //集成类型改变,如果数据库的值不为空则清空
                    record.setShowmodel(null);
                    record.setResolution(null);
                }
                if(resExtIntegrate.getChartmodel() != null) {
                    record.setChartmodel(resExtIntegrate.getChartmodel());
                }
                if(resExtIntegrate.getChartheight() != null) {
                    record.setChartheight(resExtIntegrate.getChartheight());
                }
                if(resExtIntegrate.getChartwidth() != null) {
                    record.setChartwidth(resExtIntegrate.getChartwidth());
                }
                return resExtIntegrateService.updateByPrimaryKeyWithBLOBs(record);
            }
        }
        return 0;
    }
 
    @ResponseBody
    @RequestMapping("/resExtIntegrate/insertSelective")
    public int insertSelective(Res_ExtIntegrate record) {
        return resExtIntegrateService.insertSelective(record);
    }
 
    @ResponseBody
    @RequestMapping("/resExtIntegrate/selectByPrimaryKey")
    public Res_ExtIntegrate selectByPrimaryKey(int resourceid) {
        return resExtIntegrateService.selectByPrimaryKey(resourceid);
    }
 
    @ResponseBody
    @RequestMapping("/resExtIntegrate/updateByPrimaryKeySelective")
    public int updateByPrimaryKeySelective(Res_ExtIntegrate record) {
        return resExtIntegrateService.updateByPrimaryKeySelective(record);
    }
 
    @ResponseBody
    @RequestMapping("/resExtIntegrate/updateByPrimaryKeyWithBLOBs")
    public int updateByPrimaryKeyWithBLOBs(Res_ExtIntegrate record) {
        return resExtIntegrateService.updateByPrimaryKeyWithBLOBs(record);
    }
 
    @ResponseBody
    @RequestMapping("/resExtIntegrate/updateByPrimaryKey")
    public int updateByPrimaryKey(Res_ExtIntegrate record) {
        return resExtIntegrateService.updateByPrimaryKey(record);
    }
 
    /**
     * 获取关联业务图层图层字段列表
     * @param ResourceId  业务图层资源ID
     * @return
     */
    @ResponseBody
    @RequestMapping("/resExtIntegrate/getGLTCFiled")
    public String getGLTCFiled(Integer ResourceId)
    {
        try
        {
            Res_ExtMapUrl resExtMapUrl = resExtMapUrlService.queryFirstOrderByResId(ResourceId);
            if (resExtMapUrl != null)
            {
                if (resExtMapUrl.getServerurl() != null && !resExtMapUrl.getServerurl().isEmpty())
                {
                    String url = resExtMapUrl.getServerurl().substring(resExtMapUrl.getServerurl().lastIndexOf("//") + 2);
                    if (url != null && !url.isEmpty())
                    {
                        String filedList = GetYWTCFiled(resExtMapUrl.getServerurl());
                        return filedList;
                    }
                }
            }
        }
        catch(Exception e)
        {
            return "[]";
        }
        return "[]";
    }
 
    /**
     * 获取图层字段
     * @param ServerURL 服务地址
     * @return
     */
    public String GetYWTCFiled(String ServerURL)
    {
        try
        {
            StringBuilder sb = new StringBuilder();
            ServerURL = ServerURL + "/query?where=1%3D1&outFields=*&returnGeometry=false&f=pjson";
            String jsonStr = HttpOperateUtils.httpGet(ServerURL.trim());
            if (jsonStr != null && !jsonStr.isEmpty()) {
                JSONObject item = JSONObject.parseObject(jsonStr);
                JSONObject fieldAliases = item.getJSONObject("fieldAliases");//获取图层字段及字段别名列表
                if(fieldAliases != null && !fieldAliases.isEmpty()) {
                    Map<String, Object> map = fieldAliases.getInnerMap();
                    for(Map.Entry<String, Object> entry: map.entrySet()) {
                        if(!sb.toString().isEmpty()) sb.append(",");
                        sb.append("{name:'" + entry.getKey() + "', alias: '" + entry.getValue().toString() + "'}");
                    }
                }
            }
            return "[" + sb.toString() + "]";
        }
        catch(IOException e)
        {
            return "[]";
        }
    }
 
    //设置Chart模型
    @ResponseBody
    @RequestMapping("/resExtIntegrate/updateChartInfo")
    public int updateChartInfo(Res_ExtIntegrate record) {
        int result = resExtIntegrateService.updateChartInfo(record);
        return result;
    }
 
    /**
     * 获取Chart模型
     * @param serverurl  服务地址
     * @return
     */
    @ResponseBody
    @RequestMapping("/resExtIntegrate/getChartInfo")
    public String getChartInfo(String serverurl,Integer resourceid) {
        //只有地址解析出数据才显示按钮
        StringBuilder urlResult = new StringBuilder();
        Res_ExtIntegrate resExtIntegrate = resExtIntegrateService.selectByPrimaryKey(resourceid);
        serverurl = serverurl != null ? StringEscapeUtils.unescapeHtml(serverurl) : "";
        if(resExtIntegrate != null && resExtIntegrate.getServerurl().equals(serverurl) && resExtIntegrate.getChartmodel()!=null && !resExtIntegrate.getChartmodel().isEmpty()){
            urlResult.append("{model:"+resExtIntegrate.getChartmodel());
            urlResult.append(",width:"+resExtIntegrate.getChartwidth());
            urlResult.append(",height:"+resExtIntegrate.getChartheight()+"}");
        }else{
            try {
                urlResult.append(httpGet(serverurl));
            } catch (Exception e) {
            }
        }
        return urlResult.toString();
    }
}