多单位版国产化地质资料管理系统
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
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
package com.zbooksoft.gdmis.controller;
 
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.ruili.wcp.common.CustomConfigUtil;
import com.ruili.wcp.configsettting.SystemConfig;
import com.ruili.wcp.data.entity.management.Dept;
import com.ruili.wcp.data.entity.management.User;
import com.ruili.wcp.service.config.ViewService;
import com.ruili.wcp.service.management.DeptService;
import com.ruili.wcp.service.management.RoleService;
import com.ruili.wcp.service.management.UserService;
import com.ruili.wcp.web.common.UserFriendlyException;
import com.ruili.wcp.web.model.easyui.TreeVO;
import com.zbooksoft.gdmis.config.ArchivesCustomConfig;
import com.zbooksoft.gdmis.data.entity.*;
import com.zbooksoft.gdmis.service.*;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authz.annotation.RequiresUser;
import org.apache.shiro.session.Session;
import org.apache.shiro.subject.Subject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;
 
import java.util.*;
 
/**
 * 档案浏览控制器
 *
 * @author PanYi
 */
@Controller
@RequestMapping("/fileView")
public class FileViewController {
 
    @Autowired
    ViewService viewService;
    @Autowired
    CatAjjxxService catAjjxxService;
    @Autowired
    CatCgwjxxService catCgwjxxService;
 
    @Autowired
    CatSwyxxxService catSwyxxxService;
    @Autowired
    CatSwajxxService catSwajxxService;
    @Autowired
    CatYswjxxService catYswjxxService;
    @Autowired
    CustomConfigUtil customConfigUtil;
 
    @Autowired
    BorrowDetailService borrowDetailService;
    @Autowired
    ProcessingDetailService processingDetailService;
    @Autowired
    JdbcTemplate jdbcTemplate;
    @Autowired
    UtilizationUserService utilizationUserService;
 
    @Autowired
    UserService userService;
 
    @Autowired
    DeptService deptService;
    @Autowired
    RoleService roleService;
 
    private static final Logger logger = LoggerFactory.getLogger(FileViewController.class);
 
 
    /**
     * 档案浏览首页
     *
     * @return
     * @throws Exception
     */
    @RequestMapping(value = {"", "index"})
    @RequiresUser
    public ModelAndView index(Long keyId, Integer fileType, String keyword) throws Exception {
        ModelAndView mav = new ModelAndView("gh/fileView/index");//指向index.jsp文件
        mav.addObject("keyId", keyId);
        mav.addObject("fileType", fileType);
        mav.addObject("keyword", keyword);
        if (fileType == 0) {
            CatAjjxx catAjjxx = catAjjxxService.getById(keyId);
            mav.addObject("title", catAjjxx.getZlmc());
        } else if (fileType == 1) {
            CatYswjxx catYswjxx = catYswjxxService.getById(keyId);
            mav.addObject("title", catYswjxx.getWjtm());
        } else if (fileType == 2) {
            CatCgwjxx catCgwjxx = catCgwjxxService.getById(keyId);
            mav.addObject("title", catCgwjxx.getWjtm());
        }
        return mav;
    }
 
    /**
     * 获取文件列表
     *
     * @param
     * @param keyId
     * @return
     */
    @RequestMapping(value = "/getFileList", produces = "application/json; charset=utf-8")
    @ResponseBody
    @RequiresUser
    public Object getFileList(Long keyId, Integer fileType) {//keyId  attatchId   value是对应档案的id、
 
        Subject currentUser = SecurityUtils.getSubject();
        Session session = currentUser.getSession();
        User user = (User) session.getAttribute("user");
 
        String deptName = user.getDeptName();
        Integer userSecurityCode = 3;
        if (deptName != null && "外部用户".equals(deptName)) {
            QueryWrapper<UtilizationUser> utilizationUserQueryWrapper = new QueryWrapper<>();
            utilizationUserQueryWrapper.eq("user_id", user.getUserId());
            UtilizationUser utilizationUser = utilizationUserService.getOne(utilizationUserQueryWrapper);
//            userSecurityCode = utilizationUser.getSecurityCode();
        }
 
        List<TreeVO> list = new ArrayList<>();
 
        if (fileType == 0) {
            QueryWrapper<CatCgwjxx> queryWrapper = new QueryWrapper<>();
            queryWrapper.eq("aj_id", keyId);
            List<CatCgwjxx> catCgwjxxList = catCgwjxxService.list(queryWrapper);
            for (CatCgwjxx catCgwjxx : catCgwjxxList) {
                try {
                    //            if (catCgwjxx.getSecurityCode() == null || (catCgwjxx.getSecurityCode() != null && catCgwjxx.getSecurityCode() <= userSecurityCode)) {
                    TreeVO vo = new TreeVO();
                    vo.setId(catCgwjxx.getId());
                    vo.setText(catCgwjxx.getWjtm());
                    String lllj = catCgwjxx.getCddzwjlj();
                    if (lllj != null) {
                        String extension = lllj.substring(lllj.lastIndexOf('.'));
                        String iconCls = getFileIconCls(extension);
                        vo.setIconCls("fa " + iconCls);
                    } else {
                        String iconCls = getFileIconCls(".pdf");
                        vo.setIconCls("fa " + iconCls);
                    }
                    Map<String, Object> attributes = new HashMap<>();
                    attributes.put("isFile", true);
                    vo.setAttributes(attributes);
                    list.add(vo);
                } catch (Exception e) {
 
                }
            }
 
            QueryWrapper<CatYswjxx> ysQueryWrapper = new QueryWrapper<>();
            ysQueryWrapper.eq("aj_id", keyId);
            List<CatYswjxx> catYswjxxList = catYswjxxService.list(ysQueryWrapper);
            for (CatYswjxx catYswjxx : catYswjxxList) {
                try {
                    //            if (catCgwjxx.getSecurityCode() == null || (catCgwjxx.getSecurityCode() != null && catCgwjxx.getSecurityCode() <= userSecurityCode)) {
                    TreeVO vo = new TreeVO();
                    vo.setId(catYswjxx.getId());
                    vo.setText(catYswjxx.getWjtm());
                    String lllj = catYswjxx.getWjlj();
                    if (lllj != null) {
                        String extension = lllj.substring(lllj.lastIndexOf('.'));
                        String iconCls = getFileIconCls(extension);
                        vo.setIconCls("fa " + iconCls);
                    } else {
                        String iconCls = getFileIconCls(".pdf");
                        vo.setIconCls("fa " + iconCls);
                    }
                    Map<String, Object> attributes = new HashMap<>();
                    attributes.put("isFile", true);
                    vo.setAttributes(attributes);
                    list.add(vo);
                } catch (Exception e) {
 
                }
            }
        } else if (fileType == 1) {
            CatYswjxx catYswjxx = catYswjxxService.getById(keyId);
            TreeVO vo = new TreeVO();
            vo.setId(catYswjxx.getId());
            vo.setText(catYswjxx.getWjtm());
            String lllj = catYswjxx.getWjlj();
            if (lllj != null) {
                String extension = lllj.substring(lllj.lastIndexOf('.'));
                String iconCls = getFileIconCls(extension);
                vo.setIconCls("fa " + iconCls);
            } else {
                String iconCls = getFileIconCls(".pdf");
                vo.setIconCls("fa " + iconCls);
            }
 
            Map<String, Object> attributes = new HashMap<>();
            attributes.put("isFile", true);
            vo.setAttributes(attributes);
            list.add(vo);
        } else if (fileType == 2) {
            CatCgwjxx catCgwjxx = catCgwjxxService.getById(keyId);
            TreeVO vo = new TreeVO();
            vo.setId(catCgwjxx.getId());
            vo.setText(catCgwjxx.getWjtm());
            String lllj = catCgwjxx.getCddzwjlj();
            if (lllj != null) {
                String extension = lllj.substring(lllj.lastIndexOf('.'));
                String iconCls = getFileIconCls(extension);
                vo.setIconCls("fa " + iconCls);
            } else {
                String iconCls = getFileIconCls(".pdf");
                vo.setIconCls("fa " + iconCls);
            }
 
            Map<String, Object> attributes = new HashMap<>();
            attributes.put("isFile", true);
            vo.setAttributes(attributes);
            list.add(vo);
        }
        return list;
    }
 
    //borrow_approval_hn.ureport%202.xml
    private String getFileIconCls(String extension) {
        String iconCls = "";
        switch (extension.toLowerCase()) {
            case ".doc":
            case ".docx":
                iconCls = "fa-file-word-o";
                break;
            case ".xls":
            case ".xlsx":
                iconCls = "fa-file-excel-o";
                break;
            case ".ppt":
            case ".pptx":
                iconCls = "fa-file-powerpoint-o";
                break;
            case ".pdf":
                iconCls = "fa-file-pdf-o";
                break;
            case ".txt":
                iconCls = "fa-file-text-o";
                break;
            case ".jpg":
            case ".png":
            case ".bmp":
            case ".jpeg":
            case ".gif":
            case ".tif":
                iconCls = "fa-file-image-o";
                break;
            case ".cda":
            case ".wav":
            case ".mp3":
            case ".mid":
            case ".wma":
            case ".aif":
            case ".aiff":
            case ".ra":
            case ".ape":
            case ".au":
            case ".ogg":
            case ".m3u8":
                iconCls = "fa-file-audio-o";
                break;
            case ".avi":
            case ".mov":
            case ".asf":
            case ".rm":
            case ".mpeg":
            case ".mpg":
            case ".dat":
            case ".qt":
            case ".wmv":
            case ".mp4":
            case ".webm":
            case ".ogv":
                iconCls = "fa-file-video-o";
                break;
            default:
                iconCls = "fa-file-o";
                break;
        }
 
        return iconCls;
    }
 
    /**
     * 浏览文件
     *
     * @param keyId
     * @param type  0 成果文件 1原始文件
     * @return
     * @throws Exception
     */
    @RequestMapping("viewFile")
    @RequiresUser
    public ModelAndView viewFile(String keyId, Integer type, String keyword) throws Exception {
 
        Subject currentUser = SecurityUtils.getSubject();
        Session session = currentUser.getSession();
        User user = (User) session.getAttribute("user");
        SystemConfig config = SystemConfig.getInstance();
        String[] dirs = config.getExternalVirtualDirectory().split(";");
 
        String viewPath = "";
        String secretPageNumber = "";
        // 转发到平台的文件浏览页面
 
        ModelAndView mav = new ModelAndView("redirect:/general/viewFile");
        mav.addObject("keyword", keyword);
        if (type == 2) {
            CatCgwjxx catCgwjxx = catCgwjxxService.getById(keyId);
            viewPath = catCgwjxx.getLllj();
            if (viewPath != null && (viewPath.endsWith(".pdf") || viewPath.endsWith(".pdf"))) {
                //判断前置页码
                secretPageNumber = catCgwjxx.getSmym();
                String newSecretPageNumber = "";
                int qzyInt = 0;
                String qzy = catCgwjxx.getQzy();
                try {
                    if (StringUtils.isNotBlank(qzy)) {
                        qzyInt = Integer.parseInt(qzy);
                        String[] split = secretPageNumber.split(",");
                        for (int i = 0; i < split.length; i++) {
                            int parseInt = Integer.parseInt(split[i]);
                            int qzyIntAll = qzyInt + parseInt;
                            newSecretPageNumber += qzyIntAll + ",";
                        }
                        secretPageNumber = newSecretPageNumber.substring(0, newSecretPageNumber.length() - 1);
                    }
                } catch (Exception e) {
                    logger.error("前页码转换异常:{}", qzy);
                }
            }
 
        } else if (type == 1) {
            CatYswjxx catYswjxx = catYswjxxService.getById(keyId);
            viewPath = catYswjxx.getWjlj();
 
        } else if (type == 0) {
            CatCgwjxx catCgwjxx = catCgwjxxService.getById(keyId);
            if (catCgwjxx != null) {
                viewPath = catCgwjxx.getLllj();
            } else {
                CatYswjxx catYswjxx = catYswjxxService.getById(keyId);
                viewPath = catYswjxx.getWjlj();
            }
        } else {
            String attachExtension = "该附件不存在!";
            session.setAttribute("browse_", false);
            throw new UserFriendlyException("错误提示", attachExtension);
        }
        if (viewPath == null) {
            String attachExtension = "该附件不存在!";
            session.setAttribute("browse_", false);
            throw new UserFriendlyException("错误提示", attachExtension);
        }
        String attachViewUrl = "";
        for (int i = 0; i < dirs.length; i++) {
            String dir = dirs[i];
            String[] dirArr = dir.split("\\|");
            if (dirArr.length == 2 && viewPath.contains(dirArr[0])) {
                if (viewPath.endsWith(".tif") || viewPath.endsWith(".tiff")) {
                    attachViewUrl = viewPath.replace(dirArr[0], dirArr[1]);
                } else {
                    attachViewUrl = viewPath.replace(dirArr[0], dirArr[1]);
                    attachViewUrl = attachViewUrl.replace("\\", "/");
                }
            }
        }
        if (attachViewUrl == null || attachViewUrl.equals("")) {
            String attachExtension = "该附件不存在!";
            session.setAttribute("browse_", false);
            throw new UserFriendlyException("错误提示", attachExtension);
        }
        if (!authorizeAttachPermission(Long.parseLong(keyId), type)) {
            ModelAndView customMav = new ModelAndView("gh/fileView/noAuthorize");
            return customMav;
        }
        logger.info("电子文件浏览路径:{}", attachViewUrl);
        mav.addObject("attachViewUrl", attachViewUrl);
        if (user.getUserType() != 0) {
            mav.addObject("secretPageNumber", secretPageNumber);
        }
        return mav;
    }
 
    /**
     * 档案浏览首页
     *
     * @return
     * @throws Exception
     */
    @RequestMapping("physicalView")
    @RequiresUser
    public ModelAndView physicalView(Long id) {
        ModelAndView mav = new ModelAndView("hn/fileView/physicalView");//指向index.jsp文件
        mav.addObject("id", id);
        CatSwyxxx catSwyxxx = catSwyxxxService.getById(id);
 
        String zkbh = catSwyxxx.getZkbh();
        mav.addObject("zkbh", zkbh);
 
        Long ajId = catSwyxxx.getAjId();
        CatSwajxx catSwajxx = catSwajxxService.getById(ajId);
 
        String xmmc = catSwajxx.getXmmc();
        mav.addObject("xmmc", xmmc);
 
        String sgcgzldh = catSwajxx.getSgcgzldh();
        mav.addObject("sgcgzldh", sgcgzldh);
 
        return mav;
    }
 
 
    /**
     * 判断是否已经关联附件
     *
     * @param keyId
     * @return
     */
    @RequestMapping(value = "/checkHasAttach", produces = "application/json; charset=utf-8", method = RequestMethod.POST)
    @ResponseBody
    @RequiresUser
    public Object checkHasAttach(Long keyId, Integer type) {
        try {
            boolean reg = false;
            if (type == null || keyId == null) {
                return reg;
            }
            if (type == 0) {
                CatCgwjxx catCgwjxx = catCgwjxxService.getById(keyId);
                String lllj = catCgwjxx.getLllj();
 
                if (StringUtils.isNotEmpty(lllj) && catCgwjxx != null) {
                    reg = true;
                }
//                if (catCgwjxx != null && catCgwjxx.getRelationState() != null && catCgwjxx.getRelationState() == 1) {
//                    reg = true;
//                }
            } else if (type == 1) {
                CatYswjxx catYswjxx = catYswjxxService.getById(keyId);
                String lllj = catYswjxx.getLllj();
                if (StringUtils.isNotEmpty(lllj) && catYswjxx != null) {
                    reg = true;
                }
//                if (catYswjxx != null && catYswjxx.getRelationState() != null && catYswjxx.getRelationState() == 1) {
//                    reg = true;
//                }
            }
            return reg;
        } catch (Exception e) {
            return false;
        }
    }
 
    /**
     * 判断是否有权限浏览附件
     *
     * @param type
     * @param keyId
     * @return
     */
    public boolean authorizeAttachPermission(Long keyId, Integer type) {
        //根据密级进行判断,高密级能浏览低密级文件
        ArchivesCustomConfig archivesCustomConfig = customConfigUtil.getConfigObj(ArchivesCustomConfig.class);
        boolean authorizeResult = false;
        Subject currentUser = SecurityUtils.getSubject();
        Session session = currentUser.getSession();
        User user = (User) session.getAttribute("user");
        //先判断是否是档案管理员 如果是直接可以浏览
 
        Long userId = user.getUserId();
        Set<String> roles = user.getRoles();
        if (roles.contains("档案管理员")) {
            return true;
        }
 
 
//        List<Dept> deptList = deptService.getSubDeptListByUserId(userId);
//        for (Dept dept : deptList) {
//            String deptName = dept.getDeptName();
//            if (deptName.contains("档案管理员")) {
//                return true;
//            }
//        }
 
//        QueryWrapper<UtilizationUser> utilizationUserQueryWrapper = new QueryWrapper<>();
//        utilizationUserQueryWrapper.eq("user_id", userId);
//        UtilizationUser utilizationUser = utilizationUserService.getOne(utilizationUserQueryWrapper);
//        if (utilizationUser == null) {
//            return true;
//        }
        //判断时候借阅过该文件,如果借阅过该文件,直接返回true
        Integer borrowCount = borrowDetailService.getBorrowCount(keyId, userId);
//        Integer processingCount = processingDetailService.getProcessingCount(keyId, userId);
        if (borrowCount > 0) {
            return true;
        }
 
        //判断利用用户注册是时是否可以自助浏览,如果不可以直接返回false
//        if (utilizationUser.getSelfBrowse() == null || utilizationUser.getSelfBrowse() == 0) {
//            return false;
//        }
 
//        if (archivesCustomConfig.getEnableSimple() && utilizationUser.getSelfBrowse() != null && utilizationUser.getSelfBrowse() == 1) {
//            return true;
//        }
        //判断是否有涉密证书,如果没有这能浏览 公开数据
//        String certificateNumber = utilizationUser.getCertificateNumber();
//        if (certificateNumber != null && !("").equals(certificateNumber)) {
//            if (type == 0) {
//                CatCgwjxx catCgwjxx = catCgwjxxService.getById(keyId);
//                String sfsm = catCgwjxx.getSfsm();
//                if (sfsm == null || sfsm.equals("") || "否".equals(sfsm)) {
//                    return true;
//                }
//            } else if (type == 1) {
//                CatYswjxx catYswjxx = catYswjxxService.getById(keyId);
//                String sfsm = catYswjxx.getSfsm();
//                if (sfsm == null || sfsm.equals("") || "否".equals(sfsm)) {
//                    return true;
//                }
//            }
//        }
 
        //判断用户密级是否可以浏览
        Integer securityLevel = user.getSecurityLevel();
 
        if (securityLevel != null) {
            if (type == 0) {
                CatCgwjxx catCgwjxx = catCgwjxxService.getById(keyId);
                if (catCgwjxx.getSecurityCode() == null || catCgwjxx.getSecurityCode() <= securityLevel + 1) {
                    return true;
                }
            } else if (type == 1) {
                CatYswjxx catYswjxx = catYswjxxService.getById(keyId);
                if (catYswjxx.getSecurityCode() == null && catYswjxx.getSecurityCode() <= securityLevel + 1) {
                    return true;
                }
            }
        }
        return authorizeResult;
    }
}