Browse Source

公告附件下载

zhuhaiwen 3 years ago
parent
commit
3dcf64d51d

+ 4 - 3
oa-app/src/main/java/com/css/oa/exam/announce/controller/AnnounceController.java

67
    public void download(@RequestParam(value = "uuid") String uuid, HttpServletRequest request, HttpServletResponse response) {
67
    public void download(@RequestParam(value = "uuid") String uuid, HttpServletRequest request, HttpServletResponse response) {
68
        try {
68
        try {
69
            if(TextUtils.isEmpty(uuid)){
69
            if(TextUtils.isEmpty(uuid)){
70
                exportPrint(response, "未找到此文件!");
70
                exportPrint(response, "uuid不能为空");
71
                return;
71
                return;
72
            }
72
            }
73
            String token = getToken();
73
            String token = getToken();
74
            mService.setToken(token);
74
            mService.setToken(token);
75
            mService.download(uuid, request, response);
75
            mService.download(uuid, request, response);
76
        } catch (Exception e1) {
77
            e1.printStackTrace();
76
        } catch (Exception e) {
77
            e.printStackTrace();
78
            exportPrint(response, e.getMessage());
78
        }
79
        }
79
    }
80
    }
80
81

+ 6 - 2
oa-app/src/main/java/com/css/oa/exam/announce/service/AnnounceService.java

74
     *  @param uuid = OP_XM_ENCLOSURE表主键
74
     *  @param uuid = OP_XM_ENCLOSURE表主键
75
     */
75
     */
76
    @Override
76
    @Override
77
    public void download(String uuid, HttpServletRequest request, HttpServletResponse response) {
77
    public void download(String uuid, HttpServletRequest request, HttpServletResponse response) throws Exception {
78
        Admin admin = Admin.getAdminByToken(token);
78
        Admin admin = Admin.getAdminByToken(token);
79
        uploadService.download(admin, uuid, request, response);
79
        Announce announce = repository.findById(uuid).get();
80
        if(TextUtils.isEmpty(announce.getFile_id())){
81
            throw new Exception("此公告没有附件可下载");
82
        }
83
        uploadService.download(admin, announce.getFile_id(), request, response);
80
    }
84
    }
81
85
82
    @Override
86
    @Override

+ 1 - 1
oa-app/src/main/java/com/css/oa/exam/announce/service/IAnnounceService.java

13
13
14
    void add(Announce test);
14
    void add(Announce test);
15
15
16
    void download(String uuid, HttpServletRequest request, HttpServletResponse response);
16
    void download(String uuid, HttpServletRequest request, HttpServletResponse response) throws Exception;
17
17
18
    Map queryPage(AnnoQueryReq req);
18
    Map queryPage(AnnoQueryReq req);
19
19

+ 2 - 2
oa-app/src/main/java/com/css/oa/exam/util/upload/UploadService.java

65
    @Autowired
65
    @Autowired
66
    FileInfoRepository fileInfoRepository;
66
    FileInfoRepository fileInfoRepository;
67
67
68
    public void download(Admin admin, String uuid, HttpServletRequest request, HttpServletResponse response) {
68
    public void download(Admin admin, String file_id, HttpServletRequest request, HttpServletResponse response) {
69
        try {
69
        try {
70
            response.reset();
70
            response.reset();
71
            // 设置文件输出类型
71
            // 设置文件输出类型
72
            response.setContentType("multipart/form-data");
72
            response.setContentType("multipart/form-data");
73
            // 文件名编码
73
            // 文件名编码
74
            FileInfoEntity entity = fileInfoRepository.findOne(uuid);
74
            FileInfoEntity entity = fileInfoRepository.findOne(file_id);
75
            String fileName = entity.getFileName();
75
            String fileName = entity.getFileName();
76
            response.setHeader("Content-Disposition", "attachment; fileName=" + transCharacter(request, fileName));
76
            response.setHeader("Content-Disposition", "attachment; fileName=" + transCharacter(request, fileName));
77
            UploadUtil.downloadListFolderFiles(admin, entity.getUuid(), entity.getUploadPath(), fileName, entity.getCipherKey(), response);
77
            UploadUtil.downloadListFolderFiles(admin, entity.getUuid(), entity.getUploadPath(), fileName, entity.getCipherKey(), response);