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
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
package com.landtool.lanbase.modules.res.controller;
 
import java.net.URLDecoder;
import java.sql.Timestamp;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
 
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
 
import com.alibaba.fastjson.JSON;
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.Result;
import com.landtool.lanbase.config.SysTemPropertyConfig;
import com.landtool.lanbase.modules.api.utils.PageBean;
import com.landtool.lanbase.modules.org.entity.OrgUser;
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_MainInfo;
import com.landtool.lanbase.modules.res.entity.Res_Theme;
import com.landtool.lanbase.modules.res.entity.Res_Theme_Module;
import com.landtool.lanbase.modules.res.entity.Res_Theme_Relation;
import com.landtool.lanbase.modules.res.service.ResMainInfoService;
import com.landtool.lanbase.modules.res.service.ResThemeModuleService;
import com.landtool.lanbase.modules.res.service.ResThemeRelationService;
import com.landtool.lanbase.modules.res.service.ResThemeService;
import com.landtool.lanbase.modules.sys.controller.AbstractController;
import com.landtool.lanbase.modules.sys.service.SysFieldvalueService;
 
@Controller
@RequestMapping("/res/ResTheme")
public class ResThemeController extends AbstractController {
    @Autowired
    private ResThemeService resThemeService;
    
    @Autowired
    public SysTemPropertyConfig sysConfig;
    
    @Autowired
    private ResThemeRelationService resThemeRelationService;
    
    @Autowired
    private ResThemeModuleService resThemeModuleService;
    
    @Autowired
    private OrgUserService orgUserService;
 
    @Autowired
    private ResMainInfoService resMainInfoService;
 
    @Autowired
    private SysFieldvalueService FieldUtils;
 
    @Autowired
    private OrgUnitService orgUnitService;
    
    /**
     * 访问业务专题
     * @param model
     * @return
     */
    @RequestMapping("index")
    public String resThemeIndex(Model model) {
        model.addAttribute("pubzyWebRoot", sysConfig.getPubzyWebRoot());
        model.addAttribute("systemName", sysConfig.getAppFullName());
        return "/ResManage/ResTheme/index";
    }
    
    /**
     * 查询业务专题列表
     * @param resTheme
     * @param pageBean
     * @return
     */
    @ResponseBody
    @RequestMapping("selectResTheme")
    @LogAction("资源管理,业务专题,业务专题列表查询,查询")
    public Result selectResTheme(Res_Theme resTheme, PageBean pageBean) {
        PageHelper.startPage(pageBean.getPage(), pageBean.getLimit());
        List<Res_Theme> list = resThemeService.selectResTheme(resTheme);
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        int countNums = (int) ((Page) list).getTotal();
        PageBean<Res_Theme> pageData = new PageBean<>(pageBean.getPage(), pageBean.getLimit(), countNums);
        pageData.setItems(list);
 
        List<Map<String,Object>> maps = new LinkedList<>();
        for (int i = 0; i < list.size(); i++) {
            String name = "";
            String title = list.get(i).getTitle();
            if (list.get(i).getAdduserid() != null) {
                name = orgUserService.getChinesename(list.get(i).getAdduserid());
            }
            Map<String,Object> map = new HashMap<>();
            map.put("themeid",list.get(i).getThemeid());
            map.put("title",title);
            map.put("addtime",sdf.format(list.get(i).getAddtime()));
            map.put("isdefault",list.get(i).getIsdefault());
            map.put("isonemap",list.get(i).getIsonemap());
            map.put("adduserid",name);
            maps.add(map);
        }
        return Result.ok().put("topics",maps).put("totalCount",countNums);
    }
    
    /**
     * 新增业务专题
     * @param themeid
     * @return
     */
    @RequestMapping("addResTheme")
    public String AddResTheme(Integer themeid, Model model) {
        Res_Theme resTheme = new Res_Theme();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        Res_Theme_Module resThemeModule = new Res_Theme_Module();
        String name = null;
        LinkedHashMap<String, Integer> moduleList = new LinkedHashMap<String, Integer>();
        if (themeid != null) {
            resTheme = resThemeService.selectByThemeId(themeid);
            List<Res_Theme_Relation> list = resThemeRelationService.selectByIdList(themeid);
            if (list.size() != 0) {
                for (int i = 0; i < list.size(); i++) {
                    resThemeModule = resThemeModuleService.selectByid(list.get(i).getModuleid());
                    moduleList.put(resThemeModule.getTitle(),resThemeModule.getModuleid());
                }
            }
            if (resTheme.getAdduserid() != null) {
                name = orgUserService.getChinesename(resTheme.getAdduserid());
            }
            model.addAttribute("addtime", sdf.format(resTheme.getAddtime()));
            model.addAttribute("adduserName", name);
 
            if(resTheme.getResourceid() != null) {
                Res_MainInfo res_mainInfo = resMainInfoService.selectByPrimaryKey(resTheme.getResourceid());
                if(res_mainInfo != null) {
                    resTheme.setThememap(res_mainInfo.getTitle());
                }
            }
        }
        if (themeid == null) {
            //获取当前登录人id name 还有对应的单位id name 
            model.addAttribute("adduserName", getLoginName());
            model.addAttribute("addtime", sdf.format(new Date()));
        }
        model.addAttribute("moduleList", moduleList);
        model.addAttribute("resTheme", resTheme);
        model.addAttribute("themeid", themeid);
        model.addAttribute("resThemeModule", resThemeModule);
        model.addAttribute("pubzyWebRoot", sysConfig.getPubzyWebRoot());
        model.addAttribute("systemName", sysConfig.getAppFullName());
        model.addAttribute("content", resTheme.getContent());
        model.addAttribute("jspwebroot", sysConfig.getPubzyWebRoot().replace("javapubzy/", ""));// 临时处理
        return "/ResManage/ResTheme/AddResTheme";
    }
    
    @ResponseBody
    @RequestMapping("insert")
    public int insert(Res_Theme record) {
        return resThemeService.insert(record);
    }
    
    /**
     * 新增修改方法
     * @param record
     * @param moduleid
     * @return
     */
    @ResponseBody
    @RequestMapping("insertSelective")
    public String insertSelective(Res_Theme record, String moduleid) {
        String msg = "";
        if (record.getThemeid() == null) {
            if (record.getIsdefault() == null) {
                record.setIsdefault((byte) 0); //设置默认专题为0
            }
            if (record.getIsonemap() == null) {
                record.setIsonemap((byte) 0); //设置是否一张图为0
            }
            record.setOrderindex(0);  //设置排序号为0 
            record.setAdduserid(getUserId().intValue());
            Timestamp audittime = new Timestamp(new Date().getTime());//获取当前时间
            record.setAddtime(audittime);
            int r = resThemeService.insertSelective(record);
            int t = 1;
            if (moduleid != null && !moduleid.isEmpty()) {
                Res_Theme_Relation resThemeRelation = new Res_Theme_Relation();
                String[] mid = moduleid.split(",");
                for (int i = 0; i < mid.length; i++) {
                    resThemeRelation.setModuleid(Integer.valueOf(mid[i]));
                    resThemeRelation.setThemeid(record.getThemeid());
                    t = resThemeRelationService.insert(resThemeRelation);
                }
            }
            System.out.println(record.toString());
            if (r > 0 && t == 1) {
                msg = "保存成功!";
            } else {
                msg = "保存失败!";
            }
        } else {
            if (record.getIsdefault() == null) {
                record.setIsdefault((byte) 0); //设置默认专题为0
            }
            if (record.getIsonemap() == null) {
                record.setIsonemap((byte) 0); //设置是否一张图为0
            }
            int r = resThemeService.updateById(record);
            int t = 1;
            resThemeRelationService.deleteByThemeId(record.getThemeid());
            if (moduleid != null && !moduleid.isEmpty()) {
                Res_Theme_Relation resThemeRelation = new Res_Theme_Relation();
                resThemeRelationService.deleteByThemeId(record.getThemeid());
                String[] mid = moduleid.split(",");
                for (int i = 0; i < mid.length; i++) {
                    resThemeRelation.setModuleid(Integer.valueOf(mid[i]));
                    resThemeRelation.setThemeid(record.getThemeid());
                    t = resThemeRelationService.insert(resThemeRelation);
                }
            }
            if (r > 0 && t == 1) {
                msg = "更新成功!";
            } else {
                msg = "更新失败!";
            }
        }
        return "{'msg':'" + msg + "','id':'" + record.getThemeid() + "'}";
    }
 
 
    @ResponseBody
    @RequestMapping("UpModuleid")
    public String UpModuleid(String moduleid,Integer Themeid){
        int t=1;
        if (moduleid != null && !moduleid.isEmpty()) {
            Res_Theme_Relation resThemeRelation = new Res_Theme_Relation();
            resThemeRelationService.deleteByThemeId(Themeid);
            String[] mid = moduleid.split(",");
 
            for (int i = 0; i < mid.length; i++) {
                resThemeRelation.setModuleid(Integer.valueOf(mid[i]));
                resThemeRelation.setThemeid(Themeid);
                resThemeRelation.setOrderid(i);
                t = resThemeRelationService.insert(resThemeRelation);
            }
        }
        String msg="";
        if (t == 1) {
            msg = "更新成功!";
        } else {
            msg = "更新失败!";
        }
        return "{'msg':'" + msg + "'}";
    }
 
 
    @ResponseBody
    @RequestMapping("deleteById")
    @LogAction("资源管理,业务专题,业务专题删除,删除")
    public int DeleteById(Integer themeid) {
        List<Res_Theme_Relation> list = resThemeRelationService.selectByIdList(themeid);
        int t = 1;
        if (list.size() > 0) {
            t = resThemeRelationService.deleteByThemeId(themeid); //删除业务专题前把关联的信息删除
        }
        int r = resThemeService.deleteById(themeid);
        if (t > 0 && r == 1) {
            return 1;
        } else {
            return 0;
        }
    }
 
    @RequestMapping("ZhuanTiDiTu")
    public String ZhuanTiDiTu(Model model) {
        model.addAttribute("pubzyWebRoot", sysConfig.getPubzyWebRoot());
        model.addAttribute("systemName", sysConfig.getAppFullName());
        return "/ResManage/ResTheme/ZhuangTiDiTuTree";
    }
 
    /**
    * @Description: 查询有权限的专题地图
    * @author ykm
    * @return
    * @date 2018/8/10 15:38
    */
    @RequestMapping("selectThemeMapTree")
    @ResponseBody
    public String selectThemeMapTree(Res_MainInfo resMainInfo,String parentid) {
        StringBuilder sb = new StringBuilder();
        Map<String, Object> map = new HashMap<>();
        OrgUser user = getUser();
        map.put("userid", user.getUserid());
        map.put("unitid", orgUserService.getDefaultUnit(user.getUserid()).getUnitid());
        map.put("title", resMainInfo.getTitle());
        map.put("parentid", parentid);
 
        List<Res_Catalog> resCatalogs = resThemeService.selectThememapNode(map);
 
        //修改因英文单引号 '和双引号" 导致的错误 alert ykm 2019/01/08
        List<Map<String,Object>> maps = new LinkedList<>();
 
        // 循环构造子目录节点
        for (Res_Catalog resCatalog : resCatalogs) {
            Map<String, Object> nodemap = new HashMap<>();
            nodemap.put("resourceid", resMainInfo.getResourceid());
            nodemap.put("userid", user.getUserid());
            nodemap.put("unitid", orgUserService.getDefaultUnit(user.getUserid()).getUnitid());
            nodemap.put("title", resMainInfo.getTitle());
            nodemap.put("datasources", resMainInfo.getDatasources());
            nodemap.put("selectids", resMainInfo.getSelectids());
            nodemap.put("parentid", resCatalog.getCatlogid());
            int childCount = resThemeService.selectThemeMapTree(nodemap).size();
 
            Map<String, Object> remap = new HashMap<>();
            if(childCount > 0) {
                remap.put("id",resCatalog.getCatlogid());
                remap.put("name",resCatalog.getTitle());
                remap.put("title",resCatalog.getTitle());
                remap.put("isParent",true);
                remap.put("iconOpen","/image/classicons/folderOpen.png',iconClose:'/image/classicons/folderOpen.png");
                remap.put("iconClose","/image/classicons/folderOpen.png',iconClose:'/image/classicons/folder.png");
                maps.add(remap);
            }
            else {
                if(!getTreeNode(nodemap).isEmpty()) {
                    remap.put("id",resCatalog.getCatlogid());
                    remap.put("name",resCatalog.getTitle());
                    remap.put("title",resCatalog.getTitle());
                    remap.put("isParent",true);
                    remap.put("iconOpen","/image/classicons/folderOpen.png',iconClose:'/image/classicons/folderOpen.png");
                    remap.put("iconClose","/image/classicons/folderOpen.png',iconClose:'/image/classicons/folder.png");
                    maps.add(remap);
                }
            }
        }
 
        List<Res_MainInfo> list = resThemeService.selectThemeMapTree(map);
        HashMap<String, String> DataSourceList = FieldUtils.getDataSourceList();// 获取数据来源列表
        // 循环构造资源节点
        for (Res_MainInfo resMainInfo1 : list) {
            Map<String, Object> remap = new HashMap<>();
            remap.put("id","ZiYuan_" + resMainInfo1.getResourceid());
            remap.put("name",resMainInfo1.getTitle());
            remap.put("title",resMainInfo1.getDatasources());
            remap.put("isParent",false);
            remap.put("icon","/image/classicons/"+resMainInfo1.getResourceclass()+".png");
            maps.add(remap);
        }
        return JSON.toJSONString(maps, SerializerFeature.WriteMapNullValue);
    }
 
    public String getTreeNode(Map<String,Object> map) {
        StringBuilder sb = new StringBuilder();
        List<Res_Catalog> resCatalogs = resThemeService.selectThememapNode(map);
        // 循环构造子目录节点
        for (Res_Catalog resCatalog : resCatalogs) {
            Map<String, Object> nodemap = new HashMap<>();
            nodemap = map;
            nodemap.put("parentid", resCatalog.getCatlogid());
            int childCount = resThemeService.selectThemeMapTree(nodemap).size();
            if(childCount > 0) {
                if (!"".equals(sb.toString())) {
                    sb.append(',');
                }
                sb.append("{id: " + resCatalog.getCatlogid() + ",name:'" + resCatalog.getTitle() + "',title:'" + resCatalog.getTitle() + "',isParent: true}");
            }
            else {
                if(!getTreeNode(nodemap).isEmpty()) {
                    if (!"".equals(sb.toString())) {
                        sb.append(',');
                    }
                    sb.append("{id: " + resCatalog.getCatlogid() + ",name:'" + resCatalog.getTitle() + "',title:'" + resCatalog.getTitle() + "',isParent: true,icon:'/image/classicons/defaulticon.png'}");//update:dsh(2018/12/05)
                    sb.append(getTreeNode(nodemap));
                }
            }
        }
        System.out.println(sb.toString());
        return sb.toString();
    }
 
    /**
     * 自动补全输入首字母查询
     * @param keyWord
     * @return
     */
    @ResponseBody
    @GetMapping("/findPinyinByKeyWord")
    public String[] findpinyinByKeyWord(@RequestParam(name = "keyWord") String keyWord){
        keyWord = URLDecoder.decode(keyWord);
        Map<String,Object> map = new HashMap<String,Object>();
        OrgUser user = getUser();
        map.put("userid", user.getUserid());
        map.put("unitid", orgUserService.getDefaultUnit(user.getUserid()).getUnitid());
        map.put("keyWord",keyWord);
        List<Res_MainInfo> list = null;
        list = resThemeService.selectThemeMapTree(map);
        String[] arr = new String[list.size()];
        for (int i =0;i<list.size();i++) {
            String title = list.get(i).getTitle();
            arr[i] = title;
        }
        return arr;
    }
 
    /**
     * 查询业务专题排序列表
     * @return
     */
    @ResponseBody
    @RequestMapping("selectResThemeByOrderid")
    public Result selectResThemeByOrderid() {
        StringBuilder rsb = new StringBuilder();
        List<Res_Theme> list = resThemeService.selectResTheme(new Res_Theme());
//        rsb.append("[");
 
        List<Map<String,Object>> maps = new LinkedList<>();
        for (int i = 0; i < list.size(); i++) {
            String name = "";
//            if (i != 0) {
//                rsb.append(",");
//            }
//            rsb.append("{'themeid':'" + list.get(i).getThemeid() + "'");
//            rsb.append(",'title':'" + list.get(i).getTitle() + "'}");
 
            Map<String,Object> map = new HashMap<>();
            map.put("themeid",list.get(i).getThemeid());
            map.put("title",list.get(i).getTitle());
            maps.add(map);
        }
//        rsb.append("]");
        return Result.ok().put("result",maps);
    }
 
    /**
     * 更改排序
     * @return
     */
    @ResponseBody
    @RequestMapping("updateOrderid")
    public String updateOrderid(String ids) {
        Integer result = 0;
        String[] idList = ids.split(",");
        for(int i = 0;i<idList.length;i++){
            Res_Theme model = new Res_Theme();
            model.setThemeid(Integer.parseInt(idList[i]));
            model.setOrderid(i);
            result = resThemeService.updateOrderid(model);
        }
        return "{'result':" + result + "}";
    }
 
    @RequestMapping("KongJianFuWuTree")
    public String KongJianFuWuTree(Model model,String type,Integer catlogid) {
        model.addAttribute("pubzyWebRoot", sysConfig.getPubzyWebRoot());
        model.addAttribute("systemName", sysConfig.getAppFullName());
        model.addAttribute("resourceclass", (type.equals("ExtThemeMap")?"KJ_ZTDT":"KJ_YWTC"));
        model.addAttribute("catlogid", catlogid);
        return "/ResManage/ResTheme/KongJianFuWuTree";
    }
 
    @RequestMapping("selectKongJianFuWuTree")
    @ResponseBody
    public String selectKongJianFuWuTree(Res_MainInfo resMainInfo,String parentid,String resourceclass,Integer catlogid) {
        StringBuilder resCatalogJson = new StringBuilder();
        Map<String, Object> map = new HashMap<>();
        OrgUser user = getUser();
        map.put("parentid", parentid);
        map.put("resourceclass", resourceclass);
        map.put("userid", user.getUserid());
        map.put("unitid", orgUserService.getDefaultUnit(user.getUserid()).getUnitid());
        map.put("catlogid", catlogid);
        List<Res_Catalog> resCatalogList = resThemeService.selectKongJianFuWuNode(map);// 获取子目录列表
        // 循环构造子目录节点
 
        List<Map<String, Object>> maps = new LinkedList<>();
        for (Res_Catalog resCatalog : resCatalogList) {
            Map<String, Object> catlogmap = new HashMap<>();
            catlogmap.put("id", resCatalog.getCatlogid());
            catlogmap.put("name", resCatalog.getTitle());
            catlogmap.put("title", resCatalog.getTitle());
            catlogmap.put("isParent", true);
            catlogmap.put("iconOpen", "/image/classicons/folderOpen.png");
            catlogmap.put("iconClose", "/image/classicons/folder.png");
            maps.add(catlogmap);
 
//            if (!"".equals(resCatalogJson.toString())) {
//                resCatalogJson.append(',');
//            }
//            resCatalogJson.append("{id: " + resCatalog.getCatlogid() + ",name:'" + resCatalog.getTitle()+"',title:'" + resCatalog.getTitle() +"',isParent: true"+",iconOpen:'/image/classicons/folderOpen.png',iconClose:'/image/classicons/folder.png'"+"}");
        }
        // 获取资源类型列表
        List<Res_MainInfo> resMainInfos = resThemeService.selectKongJianFuWuTree(map); // 获取目录下业务图层资源列表
        // 循环构造资源节点
        for (Res_MainInfo resMainInfo1 : resMainInfos) {
            String unitname = orgUnitService.getUnitName((long) resMainInfo1.getPubunitid());
            Map<String, Object> catlogmap = new HashMap<>();
            catlogmap.put("id", "ZiYuan_" + resMainInfo1.getResourceid());
            catlogmap.put("name", resMainInfo1.getTitle()
                    + (unitname != null && unitname.length() > 0 ? ("(" + unitname + ")") : ""));
            catlogmap.put("title", resMainInfo1.getTitle());
            catlogmap.put("isParent", false);
            catlogmap.put("icon", "/image/classicons/" + resMainInfo1.getResourceclass() + ".png");
            maps.add(catlogmap);
 
//            if (!"".equals(resCatalogJson.toString())) {
//                resCatalogJson.append(',');
//            }
//
//            resCatalogJson.append("{id: 'ZiYuan_" + resMainInfo1.getResourceid() + "',name:'" + resMainInfo1.getTitle()
//                    + (unitname != null && unitname.length() > 0 ? ("(" + unitname + ")") : "") + "', title: '"
//                    + resMainInfo1.getDatasources() + "',isParent:false,icon:'/image/classicons/" + resMainInfo1.getResourceclass() + ".png'}");//update:dsh(2018/12/05)
        }
        return JSON.toJSONString(maps, SerializerFeature.WriteMapNullValue);
    }
}