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 utilizationUserQueryWrapper = new QueryWrapper<>(); utilizationUserQueryWrapper.eq("user_id", user.getUserId()); UtilizationUser utilizationUser = utilizationUserService.getOne(utilizationUserQueryWrapper); // userSecurityCode = utilizationUser.getSecurityCode(); } List list = new ArrayList<>(); if (fileType == 0) { QueryWrapper queryWrapper = new QueryWrapper<>(); queryWrapper.eq("aj_id", keyId); List 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 attributes = new HashMap<>(); attributes.put("isFile", true); vo.setAttributes(attributes); list.add(vo); } catch (Exception e) { } } QueryWrapper ysQueryWrapper = new QueryWrapper<>(); ysQueryWrapper.eq("aj_id", keyId); List 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 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 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 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 roles = user.getRoles(); if (roles.contains("档案管理员")) { return true; } // List deptList = deptService.getSubDeptListByUserId(userId); // for (Dept dept : deptList) { // String deptName = dept.getDeptName(); // if (deptName.contains("档案管理员")) { // return true; // } // } // QueryWrapper 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; } }