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
package com.landtool.lanbase.modules.res.controller;
 
import java.io.File;
import java.io.IOException;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;
 
import org.apache.commons.io.FileUtils;
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.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;
 
import com.landtool.lanbase.common.annotation.LogAction;
import com.landtool.lanbase.config.SysTemPropertyConfig;
import com.landtool.lanbase.modules.org.service.OrgUserService;
import com.landtool.lanbase.modules.res.entity.Res_ExtMapUrl;
import com.landtool.lanbase.modules.res.entity.Res_ExtThemeMap;
import com.landtool.lanbase.modules.res.entity.Res_MainInfo;
import com.landtool.lanbase.modules.res.service.ResExtMapUrlService;
import com.landtool.lanbase.modules.res.service.ResExtThemeMapService;
import com.landtool.lanbase.modules.res.service.ResMainInfoService;
import com.landtool.lanbase.modules.sys.controller.AbstractController;
import com.landtool.lanbase.modules.sys.service.SysFieldvalueService;
 
/**
 * @Author: lizhao
 * @Date: 2018-03-05 17:33
 * @Description:7系统资源扩展(专题地图)(RES_EXTTHEMEMAP)
 */
@Controller
@RequestMapping("/res")
public class ResExtThemeMapController extends AbstractController {
 
    @Autowired
    private ResExtThemeMapService resExtThemeMapService;
 
    @Autowired
    private ResExtMapUrlService resExtMapUrlService;
 
    @Autowired
    private SysFieldvalueService FieldUtils;
 
    @Autowired
    private ResMainInfoService resMainInfoService;
 
    @Autowired
    public SysTemPropertyConfig sysConfig;
 
    @Autowired
    public OrgUserService orgUserService;
 
    /**
     * 访问资源专题地图图层信息页面
     */
    @RequestMapping("/ResManage/ResRegister/ExtThemeMap")
    public String ExtThemeMap(int resMainInfoId, Model model) {
        List<Res_ExtMapUrl> resExtMapUrlList = resExtMapUrlService.selectByCondition(resMainInfoId);
        model.addAttribute("resExtMapUrlList", resExtMapUrlList);
 
        LinkedHashMap<String, String> typeandurlList = FieldUtils.getFieldListByKey("TypeAndURL");//获取地理参考模型列表
        model.addAttribute("typeandurlList", typeandurlList);
        String typeandurlListJson = "";
        for (Map.Entry<String, String> entry : typeandurlList.entrySet()) {
            if (typeandurlListJson != "") typeandurlListJson += ",";
            typeandurlListJson += "{key:'" + entry.getKey() + "',value:'" + entry.getValue() + "'}";
        }
        model.addAttribute("typeandurlListJson", "[" + typeandurlListJson + "]");
 
        Res_ExtThemeMap resExtThemeMap = resExtThemeMapService.selectByPrimaryKey(resMainInfoId);
        if (resExtThemeMap != null) {
            Res_MainInfo res_mainInfo = resMainInfoService.selectByPrimaryKey(resMainInfoId);
            model.addAttribute("resMainInfo", res_mainInfo);
            model.addAttribute("resExtThemeMap", resExtThemeMap);
            model.addAttribute("resMainInfoId", resMainInfoId);
 
            if (resExtThemeMap.getDefaultlayerset() != null) {
                Res_MainInfo res_mainInfo1 = resMainInfoService.selectByPrimaryKey(resExtThemeMap.getDefaultlayerset());
                String name = res_mainInfo1.getTitle();
                model.addAttribute("baseMapLayerName", name);
            }
 
            LinkedHashMap<Integer, String> tucengList = new LinkedHashMap<Integer, String>();
            if (resExtThemeMap.getSublayerset() != null && !resExtThemeMap.getSublayerset().isEmpty()) {
                String[] tuceng = resExtThemeMap.getSublayerset().split(",");
                for (int i = 0; i < tuceng.length; i++) {
                    Res_MainInfo resMainInfo = resMainInfoService.selectByPrimaryKey(Integer.parseInt(tuceng[i]));
                    if(resMainInfo != null) {
                        tucengList.put(resMainInfo.getResourceid(), resMainInfo.getTitle());
                    }
                }
            }
            model.addAttribute("tucengList", tucengList);
        } else {
            Res_MainInfo res_mainInfo = new Res_MainInfo();
            model.addAttribute("resMainInfo", res_mainInfo);
            Res_ExtThemeMap resExtThemeMap1 = new Res_ExtThemeMap();
            model.addAttribute("resExtThemeMap", resExtThemeMap1);
            model.addAttribute("tucengList", new LinkedHashMap<Integer, String>());
        }
 
        LinkedHashMap<String, String> PublishSoftList = FieldUtils.getFieldListByKey("PublishSoft");//获取发布平台字典列表
        LinkedHashMap<String, String> typeList = FieldUtils.getFieldListByKey("ThemeMapType");//获取发布平台字典列表
        model.addAttribute("PublishSoftList", PublishSoftList);
        model.addAttribute("typeList", typeList);
 
        if (SecurityUtils.getSubject().isPermitted("org_user_admin")) {
            //判断当前用户是否是管理员,是管理员或是未提交的资源才可以修改资源相关信息
            model.addAttribute("admin", true);
        } else {
            model.addAttribute("admin", false);
        }
        model.addAttribute("esbHost",sysConfig.getEsbHost());
        model.addAttribute("esbUrl",sysConfig.getEsbUrl());
        String oldesbids = resExtThemeMap != null ? resExtMapUrlService.queryRsbidsByResourceid(resMainInfoId):"";
        model.addAttribute("oldesbids",oldesbids);
        model.addAttribute("ipHost",sysConfig.getIpHost());
        model.addAttribute("gisHost",sysConfig.getGisHost());
        return "ResManage/ResRegister/ExtThemeMap";
    }
 
    /**
     * 根据id 删除专题地图列表功能
     */
    @ResponseBody
    @RequestMapping("/ResExtThemeMap/deleteByPrimaryKey")
    public int deleteByPrimaryKey(int resourceid) {
 
        return resExtThemeMapService.deleteByPrimaryKey(resourceid);
    }
 
    /**
     * 插入专题地图列表功能(所有元素不能为空)
     */
    @ResponseBody
    @RequestMapping("/ResExtThemeMap/insert")
    public int insert(Res_ExtThemeMap record) {
        return resExtThemeMapService.insert(record);
    }
 
    /**
     * 插入专题地图列表功能(可以只填写必填字段)
     */
    @ResponseBody
    @RequestMapping("/ResExtThemeMap/insertSelective")
    public int insertSelective(Res_ExtThemeMap record) {
        return resExtThemeMapService.insertSelective(record);
    }
 
    /**
     * 插入专题地图列表功能(可以只填写必填字段)
     */
    @ResponseBody
    @RequestMapping("/ResExtThemeMap/insertSelectiveAndUpdate")
    @LogAction("资源管理,资源发布,资源修改,修改|zy")
    public int insertSelectiveAndUpdate(Res_ExtThemeMap record, Res_MainInfo resMainInfo, String extMapUrlStr) {
        // 插入资源支持协议与地址表
        resExtMapUrlService.deleteAndInsertMapUrlArray(record.getResourceid(),extMapUrlStr);
        Res_ExtThemeMap resExtThemeMap = resExtThemeMapService.selectByPrimaryKey(record.getResourceid());
 
        if (resExtThemeMap == null) {
            //添加
            //alter: Xxx 处理资源注册向导新增时没有ESB代理
            int mainInfoResult = 0;
            if(resMainInfo.getEspproxy() != null) {
                mainInfoResult = resMainInfoService.updateByPrimaryKeySelective(resMainInfo);
            } else {
                mainInfoResult = 1;
            }
            if(!record.getLegendurl().isEmpty()) {
                TiHuanLuJin(record.getLegendurl());
            }
            int themeMapResult = resExtThemeMapService.insertSelective(record);
            int result;
            if (mainInfoResult == 1 && themeMapResult == 1) {
                result = 1;
            } else {
                result = 0;
            }
            return result;
        } else {
            //更新
            String path = sysConfig.getUploadPath() + "ResExtThemMapServer/" + resExtThemeMap.getLegendurl();
            File file = new File(path);
            if(file.exists()) {
                file.delete();
            }
            int mainInfoResult = 0;
            if(resMainInfo.getEspproxy() != null) {
                mainInfoResult = resMainInfoService.updateByPrimaryKeySelective(resMainInfo);
            } else {
                mainInfoResult = 1;
            }
            if(!record.getLegendurl().isEmpty()) {
                TiHuanLuJin(record.getLegendurl());
            }
            int themeMapResult = resExtThemeMapService.updateByPrimaryKeyWithBLOBs(record);
            int result;
            if (mainInfoResult == 1 && themeMapResult == 1) {
                result = 1;
            } else {
                result = 0;
            }
            return result;
        }
    }
 
    //替换路径
    private void TiHuanLuJin(@RequestBody String lujin) {
        lujin = "temp/ResExtThemMapServer/" +lujin;
        String oldFileUrl=sysConfig.getUploadPath() + lujin.replace("/","\\");
        File oldFile=new File(oldFileUrl);
        String NewFileUrl=sysConfig.getUploadPath()+lujin.replace("temp/","").replace("/","\\");
        NewFileUrl=NewFileUrl.substring(0,NewFileUrl.lastIndexOf("\\"))+"\\" ;
        File NewFile=new File(NewFileUrl);
        if (!NewFile.exists()) { // 当前地址不为空,判断该路径是否存在,不存在则创建新的文件夹
            File newfilePath = new File(NewFile+"\\");
            newfilePath.mkdirs();
        }
        com.landtool.lanbase.common.utils.FileUtils.moveTotherFolders(oldFileUrl,NewFileUrl);
        if(oldFile.exists()) {
            oldFile.delete();
        }
    }
 
    /**
     * 根据id查询专题地图列表
     */
    @ResponseBody
    @RequestMapping("/ResExtThemeMap/selectByPrimaryKey")
    public Res_ExtThemeMap selectByPrimaryKey(int resourceid) {
        return resExtThemeMapService.selectByPrimaryKey(resourceid);
    }
 
    /**
     * 根据id更新专题地图列表(更新数据,数据可以为null)
     */
    @ResponseBody
    @RequestMapping("/ResExtThemeMap/updateByPrimaryKeySelective")
    public int updateByPrimaryKeySelective(Res_ExtThemeMap record) {
        return resExtThemeMapService.updateByPrimaryKeySelective(record);
    }
 
    /**
     * 根据id更新专题地图列表(更新所有数据)
     */
    @ResponseBody
    @RequestMapping("/ResExtThemeMap/updateByPrimaryKeyWithBLOBs")
    public int updateByPrimaryKeyWithBLOBs(Res_ExtThemeMap record) {
        return resExtThemeMapService.updateByPrimaryKeyWithBLOBs(record);
    }
 
    /**
     * 根据id更新专题地图列表(更新数据,但是ZITUCHENGSET 列不能更新)
     */
    @ResponseBody
    @RequestMapping("/ResExtThemeMap/updateByPrimaryKey")
    public int updateByPrimaryKey(Res_ExtThemeMap record) {
        return resExtThemeMapService.updateByPrimaryKey(record);
    }
 
    /**
     * 子图层设置页面
     */
    @RequestMapping("/ResExtThemeMap/ZiTuCengSheZhi")
    public String ziTuCengSheZhi(Model model, String selectids) {
        model.addAttribute("pubzyWebRoot", sysConfig.getPubzyWebRoot());
        model.addAttribute("systemName", sysConfig.getAppFullName());
        //获取数据来源列表
        LinkedHashMap<String, String> DataSourceList = FieldUtils.getDataSourceList();
        model.addAttribute("datasourcelist", DataSourceList);
        model.addAttribute("selectids", selectids);
        return "/ResManage/ResRegister/ZiTuCengSheZhi";
    }
 
    /**
     * 查询专题地图模块我的制图列表(此方法放到 ZhuanTiZhiTuContonller 里,方法名:getWoDeZhiTu,如果还有其他地方调用就把注释去掉。 蔡 2018-05-21)
     * @param request
     * @param pageBean
     * @return
     */
//    @ResponseBody
//    @RequestMapping(value = "/ResExtThemeMap/selectZTDTList", produces = MediaType.APPLICATION_JSON_VALUE + ";charset=utf-8")
//    public String selectZTDTList(HttpServletRequest request, PageBean pageBean) {
//        String callbackFunName = request.getParameter("callback");
//        if(callbackFunName == null || callbackFunName.isEmpty()){
//            callbackFunName = "callback";
//        }
//        PageHelper.startPage(pageBean.getPage(), pageBean.getLimit());
//        Long userid = getUserId();
//        Map<String, Object> map = new HashMap<>();
//        map.put("leixiId", "KJ_ZTDT");
//        map.put("userid", userid);
//        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("[");
//        for (int i = 0; i < res_mainInfos.size(); i++) {
//            if(i > 0) rsb.append(",");
//            rsb.append("{resourceId:" + res_mainInfos.get(i).getResourceid());
//            rsb.append(", title: '" + res_mainInfos.get(i).getTitle() + "'}");
//        }
//        rsb.append("]");
//
//        return callbackFunName + "(" + rsb.toString() + ")";
//    }
 
    /**
     * 自定义图例上传
     */
    @ResponseBody
    @RequestMapping("/ResExtThemeMap/fileUploadTuLi")
    public String fileUploadTuLi(@RequestParam("file") MultipartFile multipartFile,String legendurl) {
        if (multipartFile.isEmpty()) {
            return "请选择需要上传的文件!";
        }
 
        String[] imgTypeArr = new String[] { "jpg", "png", "gif", "bmp", "jpeg" };
        String imgType = multipartFile.getContentType();// 获取文件格式
        boolean IsImg = false;// 文件格式检查状态
        // 判断上传文件格式
        for (int i = 0; i < imgTypeArr.length; i++) {
            if (imgType.toLowerCase().endsWith(imgTypeArr[i])) {
                IsImg = true;
                break;
            }
        }
 
        if(IsImg) {
            legendurl = sysConfig.getUploadPath() + "temp/ResExtThemMapServer/" + legendurl;
            File file = new File(legendurl);
            if(file.exists()) {
                file.delete();
            }
            String name = multipartFile.getOriginalFilename();
 
            //名称
 
            String uuid = UUID.randomUUID().toString().replaceAll("-", "");
            String fileType = name.substring(name.lastIndexOf("."));
            String Filename = uuid + fileType;
 
//            String path = sysConfig.getUploadPath() + "ResExtThemMapServer\\";
            String path = sysConfig.getUploadPath() + "temp/ResExtThemMapServer/"; // 类型为文件指向文件
//            String path2 = "temp/ResExtThemMapServer/";
            File desFile = new File(path + Filename);
            String info = desFile.getAbsolutePath();
            try {
                FileUtils.copyInputStreamToFile(multipartFile.getInputStream(), desFile);
                return "{'result':'1','Path':'" + Filename + "','Filename':'" + name.substring(name.lastIndexOf("\\") + 1, name.lastIndexOf(".")) + "'}";
            } catch (IOException e) {
                e.printStackTrace();
                return "{'result':'0'}";
            }
        }
        else {
            return "{'result':'-1'}";
        }
    }
 
}