package cn.ksource.web.controller.business.pages.fileManage; import java.io.File; import java.io.IOException; import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.Map; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.apache.commons.lang.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.servlet.ModelAndView; import cn.ksource.core.page.PageInfo; import cn.ksource.core.util.AjaxUtil; import cn.ksource.core.util.ConvertUtil; import cn.ksource.core.util.DownloadUtil; import cn.ksource.core.util.ParamsMapUtil; import cn.ksource.core.util.StringUtil; import cn.ksource.core.web.SysInfo; import cn.ksource.core.web.TreeNode; import cn.ksource.core.web.WebUtil; import cn.ksource.web.Constants; import cn.ksource.web.facade.fileManage.DocFacade; import cn.ksource.web.service.file.FileService; /** * 文档管理Controller * @author peikezhan * */ @RequestMapping("/business/pages/fileManage/doc") @Controller public class DocController { @Autowired private DocFacade docFacade; @Autowired FileService fileService; /*** * 跳转到文档管理页面 * @author peikezhan */ @RequestMapping("fileManage.html") public ModelAndView fileManage(HttpServletRequest request){ ModelAndView view=new ModelAndView("/business/pages/fileManage/file/fileManage"); String user_id =WebUtil.getLoginedUserId(request); String user_name =WebUtil.getUserName(request); view.addObject("user_id",user_id ); view.addObject("user_name",user_name ); return view; } /** * 文档数据 * @author peikezhan */ @SuppressWarnings("unchecked") @RequestMapping("fileData.html") public ModelAndView fileData(HttpServletRequest request,PageInfo pageInfo) { ModelAndView modelAndView = new ModelAndView("/business/pages/fileManage/file/fileData"); Map params=ParamsMapUtil.getParameterMap(request); PageInfo info = docFacade.queryfileData(pageInfo,params); modelAndView.addObject("info", info); //查询 String pId=params.get("pId"); String up_pid=docFacade.queryUpPid(pId); modelAndView.addObject("up_pid", up_pid); modelAndView.addObject("cp_id", pId); //查询当前文件的前三级菜单 List mList=docFacade.queryParentMenu(params); Collections.reverse(mList); modelAndView.addObject("mList", mList); modelAndView.addObject("mode","common"); modelAndView.addObject("orderWay",params.get("orderWay")); modelAndView.addObject("orderType",params.get("orderType")); return modelAndView; } /** * 文档数量 * @author peikezhan */ @RequestMapping("fileCount.html") public void fileCount(HttpServletRequest request,HttpServletResponse response) { Map params=ParamsMapUtil.getParameterMap(request); int count = docFacade.queryfileCount(params); WebUtil.write(response, String.valueOf(count)); } /** * 文件搜索数据 * @author peikezhan */ @SuppressWarnings("unchecked") @RequestMapping("fileSearchData.html") public ModelAndView fileSearchData(HttpServletRequest request,PageInfo pageInfo) { ModelAndView modelAndView = new ModelAndView("/business/pages/fileManage/file/fileData"); Map params=ParamsMapUtil.getParameterMap(request); PageInfo info = docFacade.queryfileSearchData(pageInfo,params); modelAndView.addObject("info", info); modelAndView.addObject("mode","search"); modelAndView.addObject("orderWay",params.get("orderWay")); modelAndView.addObject("orderType",params.get("orderType")); return modelAndView; } /** * 文件搜索数量 * @author peikezhan */ @RequestMapping("fileSearchCount.html") public void fileSearchCount(HttpServletRequest request,HttpServletResponse response) { Map params=ParamsMapUtil.getParameterMap(request); int count = docFacade.queryfileSearchCount(params); WebUtil.write(response, String.valueOf(count)); } /** * 删除文件 * @author peikezhan */ @RequestMapping("deleteFile.html") public void deleteFile(HttpServletRequest request,HttpServletResponse response) { Map params=ParamsMapUtil.getParameterMap(request); try { docFacade.deleteFile(params); WebUtil.write(response,"1"); } catch (Exception e) { docFacade.queryfileCount(params); e.printStackTrace(); WebUtil.write(response,"0"); } } /** * 移动文件 * @author peikezhan */ @RequestMapping("moveFile.html") public void moveFile(HttpServletRequest request,HttpServletResponse response) { Map params=ParamsMapUtil.getParameterMap(request); try { docFacade.domoveFile(params); WebUtil.write(response,"1"); } catch (Exception e) { e.printStackTrace(); WebUtil.write(response,"0"); } } /** * 重命名文件 * @author peikezhan */ @RequestMapping("renameFile.html") public ModelAndView renameFile(HttpServletRequest request,HttpServletResponse response) { Map params=ParamsMapUtil.getParameterMap(request); String up_id=request.getParameter("up_id"); String js = "window.top.query('"+up_id+"');" + "window.top.hideDialog('0');"; try { docFacade.dorenameFile(params); return WebUtil.sysInfoPage(request, "操作成功!", js, SysInfo.Success,""); } catch (Exception e) { e.printStackTrace(); WebUtil.write(response,"0"); return WebUtil.sysInfoPage(request, "系统异常!", js, SysInfo.Success,""); } } /** * 获取文件夹树形结构 * @author peikezhan */ @RequestMapping(value="companyFileJson.html") public void companyFileJson(HttpServletRequest request,HttpServletResponse response){ String pid = request.getParameter("id"); Map params=ParamsMapUtil.getParameterMap(request); TreeNode root = docFacade.getCompanyFileTree(params); if (StringUtils.isBlank(pid) || pid.equalsIgnoreCase("1")) { WebUtil.write(response, root.toJson()); } else { WebUtil.write(response, root.getChildrenNodesForJson()); } } /** * 新建文件夹 * @author peikezhan */ @RequestMapping("saveFolder.html") public ModelAndView saveFolder(HttpServletRequest request,HttpServletResponse response) { Map params=ParamsMapUtil.getParameterMap(request); String up_id=request.getParameter("up_id"); String js = "window.top.query('"+up_id+"');" + "window.top.hideDialog('0');"; try { docFacade.saveFolder(params); return WebUtil.sysInfoPage(request, "操作成功!", js, SysInfo.Success,""); } catch (Exception e) { e.printStackTrace(); return WebUtil.sysInfoPage(request, "系统异常!", js, SysInfo.Success,""); } } /** * 复制文件 * @author peikezhan */ @RequestMapping("copyFile.html") public void copyFile(HttpServletRequest request,HttpServletResponse response) { Map params=ParamsMapUtil.getParameterMap(request); try { docFacade.docopyFile(params); WebUtil.write(response,"1"); } catch (Exception e) { e.printStackTrace(); WebUtil.write(response,"0"); } } /** * 下载文件 * @author peikezhan */ @RequestMapping("downloadFile.html") public void downloadFile(HttpServletRequest request,HttpServletResponse response) { String fileId = request.getParameter("fileId"); Map fileMsg = docFacade.queryFileMsg(fileId); if(null!=fileMsg && fileMsg.size()>0) { String fileName = ConvertUtil.obj2StrBlank(fileMsg.get("FILE_NAME")); String filePath = ConvertUtil.obj2StrBlank(fileMsg.get("FILE_PATH")); String basePath = request.getSession().getServletContext().getRealPath(""); System.out.println("path------------------------>"+basePath+filePath); File file = new File(basePath+filePath); try { DownloadUtil.download(response, file, fileName, false); } catch (IOException e) { e.printStackTrace(); } } } //********************************************我的文档***************************************************************** /*** * 跳转到文档管理页面 * @author peikezhan */ @RequestMapping("myFile.html") public ModelAndView myFile(HttpServletRequest request){ ModelAndView view=new ModelAndView("/business/pages/fileManage/file/myFileList"); return view; } /** * 文档管理数据 * @author peikezhan */ @RequestMapping("myFileData.html") public ModelAndView myFileData(HttpServletRequest request,PageInfo pageInfo) { ModelAndView modelAndView = new ModelAndView("/business/pages/fileManage/file/myFileData"); Map params=ParamsMapUtil.getParameterMap(request); String user_id=WebUtil.getLoginedUserId(request); params.put("user_id", user_id); PageInfo info = docFacade.querymyfileData(pageInfo,params); modelAndView.addObject("info", info); return modelAndView; } /** * 文档管理数量 * @author peikezhan */ @RequestMapping("myFileCount.html") public void myFileCount(HttpServletRequest request,HttpServletResponse response) { Map params=ParamsMapUtil.getParameterMap(request); String user_id=WebUtil.getLoginedUserId(request); params.put("user_id", user_id); int count = docFacade.querymyfileCount(params); WebUtil.write(response, String.valueOf(count)); } /*** * 跳转到新增文档页面 * @author peikezhan */ @RequestMapping("toaddFile.html") public ModelAndView toaddFile(HttpServletRequest request){ ModelAndView view=new ModelAndView("/business/pages/fileManage/file/toaddFile"); return view; } /** * 提交保存 * @author peikezhan */ @RequestMapping("addFile.html") public ModelAndView addFile(HttpServletRequest request,HttpServletResponse response) { Map params=ParamsMapUtil.getParameterMap(request); fileService.uploadFile(request,null,params.get("folderId"),Constants.FILE_STATE_XZ,params.get("note")); String js = "window.top.query();" + "window.top.hideDialog('0');"; return WebUtil.sysInfoPage(request, "操作成功!", js, SysInfo.Success,""); } /** * 提交审核页面 */ @RequestMapping("tocomitFile.html") public ModelAndView tocomitFile(HttpServletRequest request){ ModelAndView view=new ModelAndView("/business/pages/fileManage/file/tocomitFile"); Map info=docFacade.queryFileMsg(request.getParameter("id")); view.addObject("info", info); return view; } /** * 执行提交审核 * @author peikezhan */ @RequestMapping("docomitFile.html") public ModelAndView docomitFile(HttpServletRequest request,HttpServletResponse response) { Map params=ParamsMapUtil.getParameterMap(request); docFacade.docomitFile(params); String js = "window.top.query();" + "window.top.hideDialog('0');"; return WebUtil.sysInfoPage(request, "操作成功!", js, SysInfo.Success,""); } /** * 跳转到修改页面 */ @RequestMapping("toeditFile.html") public ModelAndView toeditFile(HttpServletRequest request){ ModelAndView view=new ModelAndView("/business/pages/fileManage/file/toeditFile"); Map info=docFacade.queryFileMsg(request.getParameter("id")); view.addObject("info", info); return view; } /** * 执行修改 * @author peikezhan */ @RequestMapping("doeditFile.html") public ModelAndView doeditFile(HttpServletRequest request,HttpServletResponse response) { Map params=ParamsMapUtil.getParameterMap(request); docFacade.doeditFile(params); String js = "window.top.query();" + "window.top.hideDialog('0');"; return WebUtil.sysInfoPage(request, "操作成功!", js, SysInfo.Success,""); } /** * 跳转到详情 */ @RequestMapping("fileDetail.html") public ModelAndView fileDetail(HttpServletRequest request){ ModelAndView view=new ModelAndView("/business/pages/fileManage/file/fileDetail"); Map info=docFacade.queryFileMsg(request.getParameter("id")); String size=info.get("FILE_SIZE")+""; String icon=info.get("FILE_FORMAT")+""; size=StringUtil.getFileSize(Double.parseDouble(size)); icon=StringUtil.detailDocSuffer(icon); view.addObject("info", info); view.addObject("size", size); view.addObject("icon", icon); return view; } //*********************************************文档审核***************************************************** /*** * 跳转到文档审核 * @author peikezhan */ @RequestMapping("fileCheck.html") public ModelAndView fileCheck(HttpServletRequest request){ ModelAndView view=new ModelAndView("/business/pages/fileManage/file/fileCheckList"); return view; } /** * 文档审核数据 * @author peikezhan */ @RequestMapping("fileCheckData.html") public ModelAndView fileCheckData(HttpServletRequest request,PageInfo pageInfo) { ModelAndView modelAndView = new ModelAndView("/business/pages/fileManage/file/fileCheckData"); Map params=ParamsMapUtil.getParameterMap(request); String user_id=WebUtil.getLoginedUserId(request); params.put("current_id", user_id); PageInfo info = docFacade.querymyfileData(pageInfo,params); modelAndView.addObject("info", info); return modelAndView; } /** * 文档审核数量 * @author peikezhan */ @RequestMapping("fileCheckCount.html") public void fileCheckCount(HttpServletRequest request,HttpServletResponse response) { Map params=ParamsMapUtil.getParameterMap(request); String user_id=WebUtil.getLoginedUserId(request); params.put("current_id", user_id); int count = docFacade.querymyfileCount(params); WebUtil.write(response, String.valueOf(count)); } /** * 跳转到审核页面 */ @RequestMapping("tocheckFile.html") public ModelAndView tocheckFile(HttpServletRequest request){ ModelAndView view=new ModelAndView("/business/pages/fileManage/file/tocheckFile"); Map info=docFacade.queryFileMsg(request.getParameter("id")); view.addObject("info", info); return view; } /** * 执行审核 * @author peikezhan */ @RequestMapping("docheckFile.html") public ModelAndView docheckFile(HttpServletRequest request,HttpServletResponse response) { Map params=ParamsMapUtil.getParameterMap(request); docFacade.docheckFile(params); String js = "window.top.query();" + "window.top.hideDialog('0');"; return WebUtil.sysInfoPage(request, "操作成功!", js, SysInfo.Success,""); } //*********************************************文档查询***************************************************** /*** * 跳转到文档管理页面 * @author peikezhan */ @RequestMapping("fileSearchManage.html") public ModelAndView fileSearchManage(HttpServletRequest request){ ModelAndView view=new ModelAndView("/business/pages/fileManage/file/fileSearchManage"); String user_id =WebUtil.getLoginedUserId(request); String user_name =WebUtil.getUserName(request); return view; } /*** * 跳转到文件夹树 * @author peikezhan */ @RequestMapping("toFileTree.html") public ModelAndView toFileTree(HttpServletRequest request){ ModelAndView view=new ModelAndView("/business/pages/fileManage/file/toFileTree"); return view; } //*******************************************文档管理操作菜单****************************************************** /** * 跳转到重命名页面 */ @RequestMapping("toReName.html") public ModelAndView toReName(HttpServletRequest request){ ModelAndView view=new ModelAndView("/business/pages/fileManage/file/toReName"); String name = request.getParameter("name"); if(StringUtil.notEmpty(name)) { name = AjaxUtil.decode(name); } view.addObject("name", name); return view; } /** * 跳转到新建文件夹页面 */ @RequestMapping("toNewFloder.html") public ModelAndView toNewFloder(HttpServletRequest request){ ModelAndView view=new ModelAndView("/business/pages/fileManage/file/toNewFloder"); return view; } /*** * 跳转到移动文档页面 * @author peikezhan */ @RequestMapping("toMoveFile.html") public ModelAndView toMoveFile(HttpServletRequest request){ ModelAndView view=new ModelAndView("/business/pages/fileManage/file/toMoveFile"); return view; } /*** * 跳转到复制文档页面 * @author peikezhan */ @RequestMapping("toCopyFile.html") public ModelAndView toCopyFile(HttpServletRequest request){ ModelAndView view=new ModelAndView("/business/pages/fileManage/file/toCopyFile"); return view; } }