zhuguifei
2026-03-10 58402bd5e762361363a0f7d7907153c77dbb819f
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
package com.shlanbao.tzsc.pms.file.docfile.controller;
 
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.util.List;
import java.util.ResourceBundle;
 
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
 
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
 
import com.shlanbao.tzsc.base.controller.BaseController;
import com.shlanbao.tzsc.base.mapping.DocFile;
import com.shlanbao.tzsc.base.model.Json;
import com.shlanbao.tzsc.pms.file.docfile.beans.DocFileBean;
import com.shlanbao.tzsc.pms.file.docfile.service.DocFileServiceI;
import com.shlanbao.tzsc.utils.tools.FileOptionsUtil;
 
@Controller
@RequestMapping("/pms/file/docfile")
public class DocFileController extends BaseController {
    @Autowired
    private DocFileServiceI docFileServiceI;
    private static final ResourceBundle bundle = ResourceBundle.getBundle("config");
    /*
     * 全查
     */
    @ResponseBody
    @RequestMapping("getList")
    public List<DocFileBean> getList(HttpServletRequest request) throws Exception {
        //保存预览地址
        request.setAttribute("service_url", bundle.getString("service_url")+bundle.getString("upload_pdf"));
        return docFileServiceI.getDocFileAll(null);
    }
 
 
    /**
     * 功能说明:wct文档管理-预览 (跳转)
     * @author wanchanghuang
     * @createTime 2015年12月2日14:26:56
     * */
    @RequestMapping("gotoView")
    public void gotoView(HttpServletResponse response, HttpServletRequest request,HttpSession session,String fileurl) {
//        String path=bundle.getString("save_url")+bundle.getString("upload_pdf")+"/"+fileurl;
//        session.setAttribute("service_url", path);
//        try {
//            response.sendRedirect(request.getContextPath()+"/pms/FileManage/flexpaper/readFile.jsp");
//        } catch (IOException e) {
//            // TODO Auto-generated catch block
//            e.printStackTrace();
//        }
        String path=bundle.getString("service_url")+bundle.getString("upload_pdf")+"/"+fileurl;
        try {
            response.sendRedirect(path);
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
 
 
    @RequestMapping("fileuploadJsp")
    public String getfileuploadJsp() {
        return "/pms/file/docfile/fileupload";
    }
 
    /*
     * 上传
     */
    @ResponseBody
    @RequestMapping("uploadfile")
    public Json uploadfile(String parentId, HttpServletRequest request,
            HttpSession session) {
        Json json = new Json();
        try {
            String err= docFileServiceI.uploadDocFile(parentId, request, session);
            json.setMsg("文件上传成功!");
            json.setSuccess(true);
            if(err!=null){
                json.setMsg(err);
                json.setSuccess(false);
            }
        } catch (Exception e) {
            log.error("文件上传异常", e);
            json.setMsg("文件上传失败!");
            json.setSuccess(false);
        }
        return json;
 
    }
 
    /*
     * 下载
     */
    @RequestMapping("filedownload")
    public void filedownload(HttpServletRequest request,
            HttpServletResponse response)  {
        String fileurl = request.getParameter("fileurl");//.html
        String fileType = request.getParameter("fileType");
        String fileName = request.getParameter("fileName")+"."+fileType;
        String filePath = bundle.getString("save_url")+bundle.getString("upload")+fileurl.substring(fileurl.lastIndexOf("/"));//文件绝对路径
        //System.out.println("down file="+filePath);
        boolean bool = FileOptionsUtil.download2(filePath, fileName, response);
        if (bool) {
            log.info("下载成功");
        } else {
            log.error("下载失败");
        }
 
    }
 
    /*
     * 删除文件
     */
    @ResponseBody
    @RequestMapping("deleteFile")
    public Json deleteFile(String ids) {
        Json json = new Json();
        try {
            String err= docFileServiceI.deleteFile(ids);
            json.setMsg("删除产品规程文档成功!");
            json.setSuccess(true);
            if(err!=null){
                json.setMsg(err);
                json.setSuccess(false);
            }
        } catch (Exception e) {
            log.error(message, e);
            json.setMsg("删除产品规程文档失败!");
            json.setSuccess(false);
        }
        return json;
    }
 
    @RequestMapping("fileAddJsp")
    public String fileAddJsp() {
        return "/pms/file/docfile/fileAdd";
    }
    /**
     * 文件夹添加
     * */
    @ResponseBody
    @RequestMapping("savefile")
    public Json savefile(String parentId, HttpServletRequest request,
            HttpSession session, String filename) {
        Json json = new Json();
        try {
            String err= docFileServiceI.saveFile(parentId, filename, request, session);
 
            json.setMsg("文件夹添加成功!");
            json.setSuccess(true);
            if(err!=null){
                json.setMsg(err);
                json.setSuccess(false);
            }
        } catch (Exception e) {
            log.error("文件夹添加异常", e);
            json.setMsg("文件夹添加失败!");
            json.setSuccess(false);
        }
        return json;
    }
    @RequestMapping("fileupdateJsp")
    public String fileupdateJsp(String id,HttpServletRequest request) throws Exception{
        DocFile docfile=  docFileServiceI.DocFileById(id);
        request.setAttribute("file", docfile);
        return "/pms/file/docfile/fileupdate";
    }
    @ResponseBody
    @RequestMapping("updatefilename")
    public Json updatefilename(DocFileBean fileBean,HttpSession session){
        Json json = new Json();
        try {
            String err= docFileServiceI.updatefile(fileBean,session);
            json.setMsg("文件修改成功!");
            json.setSuccess(true);
                if(err!=null){
                json.setMsg(err);
                json.setSuccess(false);
                }
        } catch (Exception e) {
            log.error("文件修改异常", e);
            json.setMsg("文件修改失败!");
            json.setSuccess(false);
        }
        return json;
    }
 
}