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
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
package com.landtool.lanbase.modules.res.controller;
 
import java.io.File;
import java.io.IOException;
import java.net.URLEncoder;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
 
import javax.servlet.http.HttpServletRequest;
 
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.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.serializer.SerializerFeature;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.landtool.lanbase.common.annotation.LogAction;
import com.landtool.lanbase.common.utils.CommonUtils;
import com.landtool.lanbase.common.utils.HttpOperateUtils;
import com.landtool.lanbase.config.SysTemPropertyConfig;
import com.landtool.lanbase.modules.api.utils.PageBean;
import com.landtool.lanbase.modules.org.entity.OrgUnit;
import com.landtool.lanbase.modules.org.service.OrgUnitService;
import com.landtool.lanbase.modules.org.service.OrgUserService;
import com.landtool.lanbase.modules.res.entity.Res_Catalog;
import com.landtool.lanbase.modules.res.entity.Res_DiyLayerInfo;
import com.landtool.lanbase.modules.res.entity.Res_ExtFileSource;
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.ResDiyLayerInfoService;
import com.landtool.lanbase.modules.res.service.ResExtFileSourceService;
import com.landtool.lanbase.modules.res.service.ResExtMapUrlService;
import com.landtool.lanbase.modules.res.service.ResMainInfoService;
import com.landtool.lanbase.modules.res.service.ZhuanTiZhiTuService;
import com.landtool.lanbase.modules.sys.controller.AbstractController;
import com.landtool.lanbase.modules.sys.service.SysFieldvalueService;
 
/**
 * 专题制图
 */
@Controller
@RequestMapping("/res/zhuantizhitu")
public class ZhuanTiZhiTuController extends AbstractController {
    @Autowired
    private SysTemPropertyConfig sysConfig;
 
    @Autowired
    private ResMainInfoService resMainInfoService;
 
    @Autowired
    private ZhuanTiZhiTuService zhuanTiZhiTuService;
 
    @Autowired
    private ResExtMapUrlService resExtMapUrlService;
 
    @Autowired
    private ResDiyLayerInfoService resDiyLayerInfoService;
 
    @Autowired
    private OrgUserService orgUserService;
 
    @Autowired
    private OrgUnitService orgUnitService;
 
    @Autowired
    private SysFieldvalueService FieldUtils;
 
    @Autowired
    private ResExtFileSourceService resExtFileSourceService;
 
    /**
     * 主页
     */
    @RequestMapping("/index")
    public String index(Model model) {
        model.addAttribute("pubzyWebRoot", sysConfig.getPubzyWebRoot());
        model.addAttribute("systemName", sysConfig.getAppFullName());
        model.addAttribute("id", getUserId());
        model.addAttribute("gisPortal", sysConfig.getGisPortal());
        model.addAttribute("backstageWebRoot", sysConfig.getApiServer() + "/");
        return "zhuantizhitu/index";
    }
 
    /**
     * 数据资源 - 我的制图
     * @param request
     * @param pageBean
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/getWoDeZhiTu")
    @LogAction("地图服务,我的制图,我的制图查询,查询")
    public String getWoDeZhiTu(HttpServletRequest request, PageBean pageBean) {
        String callbackFunName = request.getParameter("callback");
        if(callbackFunName == null || callbackFunName.isEmpty()){
            callbackFunName = "callback";
        }
        pageBean.setLimit(10);
        PageHelper.startPage(pageBean.getPage(), pageBean.getLimit());//设置当前页数及每页条数
        Long userid = getUserId();//获取登录用户ID
 
        //构造查询对象
        Map<String, Object> map = new HashMap<>();
        map.put("leixiId", "KJ_ZTDT");//资源类型
        map.put("userid", userid);//用户ID
 
        List<Res_MainInfo> res_mainInfos = resMainInfoService.selectZTDTList(map);
        int countNums = (int) ((Page) res_mainInfos).getTotal();//获取记录总数
        PageBean<Res_MainInfo> pageData = new PageBean<>(pageBean.getPage(), pageBean.getLimit(), countNums);
        pageData.setItems(res_mainInfos);
 
        StringBuilder rsb = new StringBuilder();
        rsb.append("[");
 
        List<Map<String, Object>> maps = new LinkedList<>();
        for (int i = 0; i < res_mainInfos.size(); i++) {
            String title = res_mainInfos.get(i).getTitle();
            if(title.length() > 15) {
                title = CommonUtils.subStringUtils(title,30);
            }
            Map<String, Object> remap = new HashMap<>();
            remap.put("resourceId", res_mainInfos.get(i).getResourceid());
            remap.put("title", title);
            remap.put("fulltitle", res_mainInfos.get(i).getTitle());
            maps.add(remap);
 
//            if(i > 0) rsb.append(",");
//            rsb.append("{resourceId:" + res_mainInfos.get(i).getResourceid());
//
//            rsb.append(", title: '" + title + "'");
//            rsb.append(", fulltitle: '" + res_mainInfos.get(i).getTitle() + "'}");
        }
//        rsb.append("]");
 
        Map<String, Object> newmap = new HashMap<>();
        newmap.put("Count", countNums);
        newmap.put("Page", pageBean.getPage());
        newmap.put("ShuJu", maps);
 
        StringBuilder rsb1 = new StringBuilder();
        rsb1.append("{");
        rsb1.append("Count:"+countNums);
        rsb1.append(",Page:"+pageBean.getPage());
        rsb1.append(",ShuJu:"+ JSON.toJSONString(maps, SerializerFeature.WriteMapNullValue));
        rsb1.append("}");
        return callbackFunName + "(" + JSON.toJSONString(newmap, SerializerFeature.WriteMapNullValue) + ")";
    }
 
    /**
     * 获取业务图层列表
     * @param parentid 父节点ID
     * @param info     查询条件
     * @return
     */
    @ResponseBody
    @RequestMapping("GetYWTCList")
    @LogAction("地图服务,业务图层,业务图层列表查询,查询")
    public String getYWTCList(String parentid, Res_MainInfo info, HttpServletRequest request) {
        String callbackFunName = request.getParameter("callback");
        if(callbackFunName == null || callbackFunName.isEmpty()){
            callbackFunName = "callback";
        }
 
        //alert ykm 2019/01/23  根据用户输入的信息获取相关的用户ID
        if(info.getCreateuserid() == null && info.getFaburen() != null && !info.getFaburen().equals("")) {
            String name = getUserIds(info.getFaburen());
            info.setFaburen(name);
        }
        if(info.getCreateuserid() != null) {
            info.setFaburen(null);
        }
 
        Long userId = getUserId();  //获取用户ID
 
        StringBuilder resCatalogJson = new StringBuilder();
 
        List<Map<String, Object>> maps = new LinkedList<>(); //alert 2019/01/23
        if (parentid.indexOf("ZiYuan_") == -1) {
            Map<String, Object> map = new HashMap<>();
            map.put("parentid", parentid);
            map.put("title", info.getTitle());                  //资源名称
            map.put("createuserid", info.getCreateuserid());    //发布人
            map.put("pubdateBegin", info.getPubdateBegin());    //发布起始时间
            map.put("pubdatefinish", info.getPubdatefinish());  //发布结束时间
            map.put("iscollect", info.getIscollect());          //是否收藏
            map.put("userid", userId);                          //用户ID
 
            map.put("faburen", info.getFaburen());  //用户自己输入的发布人信息获取到的ID
 
            OrgUnit orgUnit = getUnit();                        //获取登录用户所属单位
            if(orgUnit != null) {
                map.put("unitid", orgUnit.getUnitid());         //用户单位ID
            }
            //map.put("departID", "1,2,3");                     //获取用户所属部门ID(暂无)
 
            List<Res_Catalog> resCatalogList = zhuanTiZhiTuService.getYWTCCataLogList(map);// 获取子目录列表
            // 循环构造子目录节点
 
            for (Res_Catalog resCatalog : resCatalogList) {
                Map<String, Object> catalogmap = new HashMap<>();
                catalogmap.put("id", resCatalog.getCatlogid());
                catalogmap.put("name", resCatalog.getTitle());
                catalogmap.put("isParent", true);
                catalogmap.put("iconOpen", "./images/classicons/folderOpen.png");
                catalogmap.put("iconClose", "./images/classicons/folder.png");
                maps.add(catalogmap);
 
//                if (!"".equals(resCatalogJson.toString())) {
//                    resCatalogJson.append(',');
//                }
//                resCatalogJson.append("{id: " + resCatalog.getCatlogid() + ",name:'" + resCatalog.getTitle() + "', isParent: true,iconOpen:'./images/classicons/folderOpen.png',iconClose:'./images/classicons/folder.png'}");
            }
            // 获取资源类型列表
            List<Res_MainInfo> resMainInfo = zhuanTiZhiTuService.getCatalogZiYuanList(map); // 获取目录下业务图层资源列表
            // 循环构造资源节点
            for (Res_MainInfo resMainInfo1 : resMainInfo) {
//                if (!"".equals(resCatalogJson.toString())) {
//                    resCatalogJson.append(',');
//                }
                List<Res_ExtMapUrl> urlList = resExtMapUrlService.selectByCondition(resMainInfo1.getResourceid());
                boolean isMapUrl = urlList.size() == 0 ? false : true;
                String title = resMainInfo1.getTitle();
                if (resMainInfo1.getTitle().length() > 16) {
                    title = resMainInfo1.getTitle().substring(0, 16) + "..";
                }
 
                String FaBuRen = orgUserService.getChinesename(resMainInfo1.getCreateuserid());//发布人
                String FaBuDanWei = orgUnitService.getUnitName((long) resMainInfo1.getPubunitid());//发布单位
                Res_ExtFileSource fileSource = resExtFileSourceService.selectByPrimaryKey(resMainInfo1.getResourceid());
                int isNC = (fileSource != null && fileSource.getNcconfig() != null && fileSource.getNcconfig().length() != 0) ? 1 : 0;
 
                Map<String, Object> catalogmap = new HashMap<>();
                catalogmap.put("id", "ZiYuan_" + resMainInfo1.getResourceid());
                catalogmap.put("name", title);
                catalogmap.put("title", resMainInfo1.getTitle() + "|" + FaBuDanWei + "|" + FaBuRen);
                catalogmap.put("isParent", false);
                catalogmap.put("hidtxt", "");
                catalogmap.put("isMapUrl", isMapUrl);
                catalogmap.put("isNC", isNC);
                catalogmap.put("icon", "./images/classicons/" + resMainInfo1.getResourceclass() + ".png");
                maps.add(catalogmap);
//                resCatalogJson.append("{icon:'./images/classicons/" + resMainInfo1.getResourceclass()
//                        + ".png',id: 'ZiYuan_" + resMainInfo1.getResourceid() + "',name:'" + title + "', title: '"
//                        + resMainInfo1.getTitle() + "|" + FaBuDanWei + "|" + FaBuRen
//                        + "',isParent:false, hidtxt: '', isMapUrl: " + isMapUrl + ",isNC:" + isNC + "}");
            }
        } else {
            String idstr = parentid.substring(parentid.indexOf("_") + 1, parentid.length());
            List<Res_ExtMapUrl> urlList = resExtMapUrlService.selectByCondition(Integer.parseInt(idstr));//获取资源协议信息列表
            if (urlList.size() != 0) {
                LinkedHashMap<String, String> TypeAndURLList = FieldUtils.getFieldListByKey("TypeAndURL");//获取地图服务协议字典
                for (Res_ExtMapUrl urlitem : urlList) {
//                    if (!"".equals(resCatalogJson.toString())) {
//                        resCatalogJson.append(',');
//                    }
                    String name = TypeAndURLList.get(urlitem.getTypeandurl());
 
                    Map<String, Object> catalogmap = new HashMap<>();
                    catalogmap.put("id", "Url_" + urlitem.getUrlid());
                    catalogmap.put("resourceId", idstr);
                    catalogmap.put("name", name);
                    catalogmap.put("hidtxt", "");
                    maps.add(catalogmap);
//                    resCatalogJson.append("{id: 'Url_" + urlitem.getUrlid() + "', resourceId: " + idstr + ",name:'"
//                            + name + "', hidtxt: ''}");
                }
            }
            Res_DiyLayerInfo resDiyLayerInfo = new Res_DiyLayerInfo();
            resDiyLayerInfo.setResourceid(Integer.parseInt(idstr));
            resDiyLayerInfo.setIsshare(1);
            resDiyLayerInfo.setDiyuserid(Integer.valueOf(getUserId().toString()));
            List<Res_DiyLayerInfo> resDiyLayerInfoList = resDiyLayerInfoService.queryApiList(resDiyLayerInfo);// 获取自定义图层信息列表
            if (resDiyLayerInfoList.size() > 0) {
                for (Res_DiyLayerInfo item : resDiyLayerInfoList) {
//                    if (!"".equals(resCatalogJson.toString())) {
//                        resCatalogJson.append(',');
//                    }
                    String ChineseName = orgUserService.getChinesename(item.getDiyuserid());
 
                    Map<String, Object> catalogmap = new HashMap<>();
                    catalogmap.put("id", "Diy_" + item.getDiyid());
                    catalogmap.put("resourceId", idstr);
                    catalogmap.put("name", item.getTitle() + "(" + ChineseName + ")");
                    catalogmap.put("hidtxt", "");
                    catalogmap.put("showDelBtn", (item.getDiyuserid() == userId.intValue() ? true : false));
                    maps.add(catalogmap);
//                    resCatalogJson.append("{id: 'Diy_" + item.getDiyid() + "', resourceId: " + idstr + ",name:'"
//                            + item.getTitle() + "(" + ChineseName + ")', hidtxt: '', showDelBtn: " + (item.getDiyuserid() == userId.intValue() ? true : false) + "}");
                }
            }
            Res_ExtFileSource resExtFileSource = resExtFileSourceService.selectByPrimaryKey(Integer.parseInt(idstr));
            if(resExtFileSource != null) {
                String html = getSJWJFileListHtml(resExtFileSource.getResourceid());
 
                Map<String, Object> catalogmap = new HashMap<>();
                catalogmap.put("id", "Sjwj_" + resExtFileSource.getResourceid());
                catalogmap.put("resourceId", idstr);
                catalogmap.put("html",html);
                maps.add(catalogmap);
                resCatalogJson.append("{id: \"Sjwj_" + resExtFileSource.getResourceid() + "\", resourceId: " + idstr + ",html:\"" + html +"\"}");
            }
 
        }
//        return callbackFunName + "([" + resCatalogJson.toString() + "])";
        return callbackFunName + "(" + JSON.toJSONString(maps, SerializerFeature.WriteMapNullValue) + ")";
    }
 
//    暂停使用
    @ResponseBody
    @RequestMapping("GetSJWJFileList")
    public String getSJWJFileList(Integer resourceid,HttpServletRequest request) {
        String callbackFunName = request.getParameter("callback");
        Res_ExtFileSource resExtFileSource = resExtFileSourceService.selectByPrimaryKey(resourceid);
        StringBuilder sb = new StringBuilder();
        if(resExtFileSource != null && resExtFileSource.getServerurl() != null) {
            sb.append("{Ncjsonpath:'"+ (resExtFileSource.getNcjsonpath()==null?"": resExtFileSource.getNcjsonpath())+"'");
            sb.append(",filesname:[");
            if(resExtFileSource.getSourcetype().equals("文件夹")) {
                File file = new File(sysConfig.getUploadPath() + resExtFileSource.getServerurl());
                String[] fileLists = file.list();
                if (fileLists != null) {
                    for (int i = 0; i < fileLists.length; i++) {
                        File file1 = new File(fileLists[i]);
                        if (i != 0) sb.append(",");
                        sb.append("'" + file1.getName().substring(0, file1.getName().indexOf(".")) + "'");
                    }
                }
            }
            else {
                sb.append("'" + resExtFileSource.getFilename().substring(0, resExtFileSource.getFilename().indexOf(".")) + "'");
            }
            sb.append("]}");
        }
        return callbackFunName + "(" + sb.toString() + ")";
    }
 
    private String getSJWJFileListHtml(Integer resourceid) {
        Res_ExtFileSource resExtFileSource = resExtFileSourceService.selectByPrimaryKey(resourceid);
        StringBuilder sb = new StringBuilder();
        if(resExtFileSource != null && resExtFileSource.getServerurl() != null) {
            sb.append("{Ncjsonpath:'"+ (resExtFileSource.getNcjsonpath()==null?"": resExtFileSource.getNcjsonpath())+"'");
            sb.append(",filesname:[");
            if(resExtFileSource.getSourcetype().equals("文件夹")) {
                File file = new File(sysConfig.getUploadPath() + resExtFileSource.getServerurl());
                String[] fileLists = file.list();
                if (fileLists != null) {
                    for (int i = 0; i < fileLists.length; i++) {
                        File file1 = new File(fileLists[i]);
                        if (i != 0) sb.append(",");
                        sb.append("'" + file1.getName().substring(0, file1.getName().indexOf(".")) + "'");
                    }
                }
            }
            else {
                sb.append("'" + resExtFileSource.getFilename().substring(0, resExtFileSource.getFilename().indexOf(".")) + "'");
            }
            sb.append("]}");
        }
        return sb.toString();
    }
 
    //根据输入的用户名获取用户ID
    private String getUserIds(String name) {
        String url = sysConfig.getApiServer() + "/api/org/user/findUserByWord/" + URLEncoder.encode(URLEncoder.encode(name));
 
        String username = null;
        try {
            username = HttpOperateUtils.httpGet(url);
        } catch (IOException e) {
            e.printStackTrace();
        }
        JSONArray object = JSONArray.parseArray(username);
        StringBuilder t = new StringBuilder();
        if(!name.equals( "%")) {
            for (int i = 0; i < object.size(); i++) {
                if (i != 0) t.append(",");
                t.append(object.getJSONObject(i).getString("id"));
            }
        }
        if(t.toString().equals("") && !name.equals( "%")) {
            t.append("-1");
        }
        return t.toString();
    }
}