ソースを参照

文件下载2

zhuhaiwen 3 年 前
コミット
d8757ed20f

+ 6 - 0
oa-app/src/main/java/com/css/oa/exam/announce/controller/AnnounceController.java

@ -66,6 +66,12 @@ public class AnnounceController extends BaseController {
66 66
    @GetMapping("/download")
67 67
    public void download(@RequestParam(value = "uuid") String uuid, HttpServletRequest request, HttpServletResponse response) {
68 68
        try {
69
            if(TextUtils.isEmpty(uuid)){
70
                exportPrint(response, "未找到此文件!");
71
                return;
72
            }
73
            String token = getToken();
74
            mService.setToken(token);
69 75
            mService.download(uuid, request, response);
70 76
        } catch (Exception e1) {
71 77
            e1.printStackTrace();

+ 2 - 2
oa-app/src/main/java/com/css/oa/exam/announce/repository/Announce.java

@ -44,8 +44,8 @@ public class Announce implements Serializable {
44 44
    @Column(name = "IS_TOP")
45 45
    public int is_top;
46 46
47
    @Column(name = "FILE_PATH")
48
    public String file_path;
47
    @Column(name = "FILE_ID")
48
    public String file_id;
49 49
50 50
    @Transient
51 51
    public MultipartFile file;

+ 12 - 8
oa-app/src/main/java/com/css/oa/exam/announce/service/AnnounceService.java

@ -39,11 +39,13 @@ public class AnnounceService extends BaseService implements IAnnounceService {
39 39
    @Override
40 40
    public void add(Announce obj) {
41 41
        System.out.println("传入的obj => " + obj.toString());
42
        String file_id = "";
42 43
        //上传文件
43 44
        if (obj.file != null) {
44 45
            Admin admin = Admin.getAdminByToken(token);
45
            new UploadService().upload(obj.file, admin);
46
            file_id = new UploadService().upload(obj.file, admin);
46 47
        }
48
        obj.setFile_id(file_id);
47 49
        String id = UUIDGenerator.getUUID();
48 50
        obj.setUuid(id);
49 51
        Date newDate = new Date();
@ -66,8 +68,8 @@ public class AnnounceService extends BaseService implements IAnnounceService {
66 68
    }
67 69
68 70
    /*
69
    *  @param uuid = OP_XM_ENCLOSURE表主键
70
    */
71
     *  @param uuid = OP_XM_ENCLOSURE表主键
72
     */
71 73
    @Override
72 74
    public void download(String uuid, HttpServletRequest request, HttpServletResponse response) {
73 75
        Admin admin = Admin.getAdminByToken(token);
@ -77,14 +79,16 @@ public class AnnounceService extends BaseService implements IAnnounceService {
77 79
    @Override
78 80
    public void update(Announce newObj) {
79 81
        //上传文件
82
        String file_id = "";
80 83
        if (newObj.file != null) {
81 84
            Admin admin = Admin.getAdminByToken(token);
82
            new UploadService().upload(newObj.file, admin);
85
            file_id = new UploadService().upload(newObj.file, admin);
83 86
        }
84
        Optional<Announce> byId = repository.findById(newObj.getUuid());
85
        Announce old = byId.get();
86
        CopyObjTool.copyProperties(old, newObj);
87
        repository.save(newObj);
87
        Announce old = repository.findById(newObj.getUuid()).get();
88
        if(!TextUtils.isEmpty(file_id)){
89
            old.setFile_id(file_id);
90
        }
91
        repository.save(old);
88 92
    }
89 93
90 94
    @Override

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

@ -23,7 +23,7 @@ import java.util.*;
23 23
@Slf4j
24 24
public class UploadService {
25 25
26
    public void upload(MultipartFile file, Admin admin) {
26
    public String upload(MultipartFile file, Admin admin) {
27 27
        //1,先上传
28 28
        JSONObject json = UploadUtil.upload(file, admin);
29 29
        //2,保存数据
@ -31,7 +31,7 @@ public class UploadService {
31 31
32 32
        if (json.containsKey("result") && "false".equals(json.getString("result"))) {
33 33
            log.debug("上传文档报错:" + json.getString("message"));
34
            return;
34
            return "";
35 35
        }
36 36
        FileInfoEntity entity = entity = new FileInfoEntity();
37 37
        entity.setUuid(UUIDGenerator.getUUID());
@ -57,6 +57,7 @@ public class UploadService {
57 57
        entity.setDelFlag(0);
58 58
        entity.setIsValid(1);
59 59
        fileInfoRepository.save(entity);
60
        return entity.getUuid();
60 61
    }
61 62
62 63
    @Autowired