zhuhaiwen 3 年之前
父節點
當前提交
f09d76a1fa

+ 13 - 1
oa-app/src/main/java/com/css/oa/exam/announce/controller/AnnounceController.java

@ -15,6 +15,8 @@ import org.springframework.beans.factory.annotation.Autowired;
15 15
import org.springframework.web.bind.annotation.*;
16 16
import org.springframework.web.multipart.MultipartFile;
17 17
18
import javax.servlet.http.HttpServletRequest;
19
import javax.servlet.http.HttpServletResponse;
18 20
import java.util.List;
19 21
import java.util.Map;
20 22
@ -35,7 +37,7 @@ public class AnnounceController extends BaseController {
35 37
                      @RequestParam(value = "content") String content,
36 38
                      @RequestParam(value = "is_top") int is_top,
37 39
                      @RequestParam(value = "type") int type
38
                      ) {
40
    ) {
39 41
        Result<Map> result;
40 42
        try {
41 43
            Announce announce = new Announce();
@ -60,6 +62,16 @@ public class AnnounceController extends BaseController {
60 62
        return result;
61 63
    }
62 64
65
    @ApiOperation(value = "下载公告中的文件")
66
    @GetMapping("/download")
67
    public void download(@RequestParam(value = "uuid") String uuid, HttpServletRequest request, HttpServletResponse response) {
68
        try {
69
            mService.download(uuid, request, response);
70
        } catch (Exception e1) {
71
            e1.printStackTrace();
72
        }
73
    }
74
63 75
    @ApiOperation(value = "根据考试id获取公告列表")
64 76
    @GetMapping("/queryPage")
65 77
    public Result queryPage(int type, int curPage, int pageSize) {

+ 47 - 36
oa-app/src/main/java/com/css/oa/exam/announce/service/AnnounceService.java

@ -8,8 +8,11 @@ import com.css.oa.exam.announce.bean.AnnoQueryReq;
8 8
import com.css.oa.exam.announce.repository.Announce;
9 9
import com.css.oa.exam.announce.repository.IAnnounceRepository;
10 10
import com.css.oa.exam.util.CopyObjTool;
11
import com.css.oa.exam.util.upload.FileInfoEntity;
12
import com.css.oa.exam.util.upload.FileInfoRepository;
11 13
import com.css.oa.exam.util.upload.UploadService;
12 14
import com.css.oa.utils.DateUtils;
15
import com.css.oa.utils.UUIDGenerator;
13 16
import lombok.extern.slf4j.Slf4j;
14 17
import org.apache.http.util.TextUtils;
15 18
import org.springframework.beans.factory.annotation.Autowired;
@ -22,6 +25,8 @@ import javax.persistence.criteria.CriteriaBuilder;
22 25
import javax.persistence.criteria.CriteriaQuery;
23 26
import javax.persistence.criteria.Predicate;
24 27
import javax.persistence.criteria.Root;
28
import javax.servlet.http.HttpServletRequest;
29
import javax.servlet.http.HttpServletResponse;
25 30
import java.util.*;
26 31
27 32
@Slf4j
@ -37,35 +42,49 @@ public class AnnounceService extends BaseService implements IAnnounceService {
37 42
        //上传文件
38 43
        if (obj.file != null) {
39 44
            Admin admin = Admin.getAdminByToken(token);
40
            UploadService.upload(obj.file, admin);
45
            new UploadService().upload(obj.file, admin);
41 46
        }
42
//        if (obj.getUuid() == null) {
43
//            String id = UUIDGenerator.getUUID();
44
//            obj.setUuid(id);
45
//        }
46
//        Date newDate = new Date();
47
//        if (obj.getPublish_time() == null) {
48
//            obj.setPublish_time(newDate);
49
//        }
50
//        if (obj.getCreate_time() == null) {
51
//            obj.setCreate_time(newDate);
52
//        }
53
//        if (obj.getUpdate_time() == null) {
54
//            obj.setUpdate_time(newDate);
55
//        }
56
//        if (TextUtils.isEmpty(obj.getCreate_user()) || obj.getCreate_user().equalsIgnoreCase("null")) {
57
//            obj.setCreate_user("系统");
58
//        }
59
//        if (TextUtils.isEmpty(obj.getUpdate_user()) || obj.getCreate_user().equalsIgnoreCase("null")) {
60
//            obj.setUpdate_user("系统");
61
//        }
62
//        if (obj.getDel_flag() == null) {
63
//            obj.setDel_flag("1");
64
//        }
65
//        if (obj.getRemark() == null) {
66
//            obj.setRemark("系统默认的备注");
67
//        }
68
//        repository.save(obj);
47
        String id = UUIDGenerator.getUUID();
48
        obj.setUuid(id);
49
        Date newDate = new Date();
50
        obj.setPublish_time(newDate);
51
        obj.setCreate_time(newDate);
52
        obj.setUpdate_time(newDate);
53
        if (TextUtils.isEmpty(obj.getCreate_user()) || obj.getCreate_user().equalsIgnoreCase("null")) {
54
            obj.setCreate_user("系统");
55
        }
56
        if (TextUtils.isEmpty(obj.getUpdate_user()) || obj.getCreate_user().equalsIgnoreCase("null")) {
57
            obj.setUpdate_user("系统");
58
        }
59
        if (obj.getDel_flag() == null) {
60
            obj.setDel_flag("1");
61
        }
62
        if (obj.getRemark() == null) {
63
            obj.setRemark("系统默认的备注");
64
        }
65
        repository.save(obj);
66
    }
67
68
    /*
69
    *  @param uuid = OP_XM_ENCLOSURE表主键
70
    */
71
    @Override
72
    public void download(String uuid, HttpServletRequest request, HttpServletResponse response) {
73
        Admin admin = Admin.getAdminByToken(token);
74
        new UploadService().download(admin, uuid, request, response);
75
    }
76
77
    @Override
78
    public void update(Announce newObj) {
79
        //上传文件
80
        if (newObj.file != null) {
81
            Admin admin = Admin.getAdminByToken(token);
82
            new UploadService().upload(newObj.file, admin);
83
        }
84
        Optional<Announce> byId = repository.findById(newObj.getUuid());
85
        Announce old = byId.get();
86
        CopyObjTool.copyProperties(old, newObj);
87
        repository.save(newObj);
69 88
    }
70 89
71 90
    @Override
@ -105,14 +124,6 @@ public class AnnounceService extends BaseService implements IAnnounceService {
105 124
    }
106 125
107 126
    @Override
108
    public void update(Announce newTest) {
109
        Optional<Announce> byId = repository.findById(newTest.getUuid());
110
        Announce old = byId.get();
111
        CopyObjTool.copyProperties(old, newTest);
112
        repository.save(newTest);
113
    }
114
115
    @Override
116 127
    public void delete(List<String> ids) {
117 128
        //ids = ["0","2","3"]
118 129
        repository.deleteRealByIds(ids);

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

@ -4,6 +4,8 @@ import com.css.oa.exam.announce.bean.AnnoQueryReq;
4 4
import com.css.oa.exam.announce.bean.SearchReq;
5 5
import com.css.oa.exam.announce.repository.Announce;
6 6
7
import javax.servlet.http.HttpServletRequest;
8
import javax.servlet.http.HttpServletResponse;
7 9
import java.util.List;
8 10
import java.util.Map;
9 11
@ -11,6 +13,8 @@ public interface IAnnounceService {
11 13
12 14
    void add(Announce test);
13 15
16
    void download(String uuid, HttpServletRequest request, HttpServletResponse response);
17
14 18
    Map queryPage(AnnoQueryReq req);
15 19
16 20
    void update(Announce newTest);

+ 0 - 57
oa-app/src/main/java/com/css/oa/exam/util/upload/FileInfoUtil.java

@ -1,57 +0,0 @@
1
package com.css.oa.exam.util.upload;
2
3
import net.sf.json.JSONObject;
4
import com.css.oa.utils.UUIDGenerator;
5
import io.micrometer.core.instrument.util.StringUtils;
6
import lombok.extern.slf4j.Slf4j;
7
import org.springframework.beans.factory.annotation.Autowired;
8
9
import java.util.Date;
10
11
@Slf4j
12
public class FileInfoUtil {
13
14
    private static FileInfoUtil instance;
15
16
    public static FileInfoUtil getInstance() {
17
        if (instance == null) {
18
            instance = new FileInfoUtil();
19
        }
20
        return instance;
21
    }
22
23
    @Autowired
24
    FileInfoRepository fileInfoRepository;
25
26
    public void saveInfo(JSONObject json) {
27
        if (json.containsKey("result") && "false".equals(json.getString("result"))) {
28
            log.debug("上传文档报错:" + json.getString("message"));
29
            return;
30
        }
31
        FileInfoEntity entity = entity = new FileInfoEntity();
32
        entity.setUuid(UUIDGenerator.getUUID());
33
        entity.setUploadSystem(json.getString("srcSystem"));
34
        entity.setUploadType(json.getString("fileType"));
35
        entity.setUploadSm("sm3");
36
        entity.setUploadPath(json.getString("sm3Path"));
37
        entity.setCipherKey(json.getString("cipherKey"));
38
        String fileSrcName = json.getString("fileSrcName");
39
        if (fileSrcName.contains("-已加密.")) {
40
            fileSrcName = fileSrcName.replace("-已加密.", ".");
41
        }
42
        entity.setFileName(fileSrcName);
43
        entity.setFileType(json.getString("fileExt"));
44
        entity.setFileSize(json.getString("fileSize"));
45
        String xmType = json.getString("xmType");
46
        if (StringUtils.isNotEmpty(xmType)) {
47
            entity.setXmType(json.getString("xmType"));
48
        }
49
        entity.setCreateTime(new Date());
50
        entity.setCreateUser(json.getString("user_id"));
51
52
        entity.setDelFlag(0);
53
        entity.setIsValid(1);
54
        fileInfoRepository.save(entity);
55
    }
56
57
}

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

@ -1,28 +1,89 @@
1 1
package com.css.oa.exam.util.upload;
2 2
3 3
import com.css.oa.exam.admin.bean.Admin;
4
import com.css.oa.utils.UUIDGenerator;
5
import io.micrometer.core.instrument.util.StringUtils;
4 6
import lombok.extern.slf4j.Slf4j;
5 7
import net.sf.json.JSONObject;
6
import org.apache.commons.lang3.StringUtils;
7 8
import org.apache.commons.lang3.tuple.Triple;
8 9
import org.apache.http.Header;
9 10
import org.apache.http.StatusLine;
10 11
import org.slf4j.Logger;
11 12
import org.slf4j.LoggerFactory;
13
import org.springframework.beans.factory.annotation.Autowired;
12 14
import org.springframework.core.io.ClassPathResource;
13 15
import org.springframework.web.multipart.MultipartFile;
14 16
17
import javax.servlet.http.HttpServletRequest;
18
import javax.servlet.http.HttpServletResponse;
15 19
import java.io.*;
20
import java.net.URLEncoder;
16 21
import java.util.*;
17 22
18 23
@Slf4j
19 24
public class UploadService {
20 25
21
    public static void upload(MultipartFile file, Admin admin) {
26
    public void upload(MultipartFile file, Admin admin) {
27
        //1,先上传
22 28
        JSONObject json = UploadUtil.upload(file, admin);
23
29
        //2,保存数据
24 30
        json.put("user_id", admin.my_unit_id);
25
        FileInfoUtil.getInstance().saveInfo(json);
31
32
        if (json.containsKey("result") && "false".equals(json.getString("result"))) {
33
            log.debug("上传文档报错:" + json.getString("message"));
34
            return;
35
        }
36
        FileInfoEntity entity = entity = new FileInfoEntity();
37
        entity.setUuid(UUIDGenerator.getUUID());
38
        entity.setUploadSystem(json.getString("srcSystem"));
39
        entity.setUploadType(json.getString("fileType"));
40
        entity.setUploadSm("sm3");
41
        entity.setUploadPath(json.getString("sm3Path"));
42
        entity.setCipherKey(json.getString("cipherKey"));
43
        String fileSrcName = json.getString("fileSrcName");
44
        if (fileSrcName.contains("-已加密.")) {
45
            fileSrcName = fileSrcName.replace("-已加密.", ".");
46
        }
47
        entity.setFileName(fileSrcName);
48
        entity.setFileType(json.getString("fileExt"));
49
        entity.setFileSize(json.getString("fileSize"));
50
        String xmType = json.getString("xmType");
51
        if (StringUtils.isNotEmpty(xmType)) {
52
            entity.setXmType(json.getString("xmType"));
53
        }
54
        entity.setCreateTime(new Date());
55
        entity.setCreateUser(json.getString("user_id"));
56
57
        entity.setDelFlag(0);
58
        entity.setIsValid(1);
59
        fileInfoRepository.save(entity);
60
    }
61
62
    @Autowired
63
    FileInfoRepository fileInfoRepository;
64
65
    public void download(Admin admin, String uuid, HttpServletRequest request, HttpServletResponse response) {
66
        try {
67
            response.reset();
68
            // 设置文件输出类型
69
            response.setContentType("multipart/form-data");
70
            // 文件名编码
71
            FileInfoEntity entity = fileInfoRepository.findOne(uuid);
72
            String fileName = entity.getFileName();
73
            response.setHeader("Content-Disposition", "attachment; fileName=" + transCharacter(request, fileName));
74
            UploadUtil.downloadListFolderFiles(admin,entity.getUuid(), entity.getUploadPath(), fileName, entity.getCipherKey(), response);
75
        } catch (Exception e) {
76
77
        }
78
    }
79
80
    private String transCharacter(HttpServletRequest request, String str) throws Exception {
81
        if (request.getHeader("USER-AGENT").toLowerCase().indexOf("msie") > 0) {
82
            return URLEncoder.encode(str, "UTF-8");
83
        } else if (request.getHeader("USER-AGENT").toLowerCase().indexOf("firefox") > 0) {
84
            return new String(str.getBytes("UTF-8"), "ISO8859-1");
85
        }
86
        return new String(str.getBytes("UTF-8"), "ISO8859-1");
26 87
    }
27 88
28 89
}

+ 46 - 0
oa-app/src/main/java/com/css/oa/exam/util/upload/UploadUtil.java

@ -10,9 +10,11 @@ import org.apache.http.StatusLine;
10 10
import org.springframework.core.io.ClassPathResource;
11 11
import org.springframework.web.multipart.MultipartFile;
12 12
13
import javax.servlet.http.HttpServletResponse;
13 14
import java.io.IOException;
14 15
import java.io.InputStream;
15 16
import java.io.InputStreamReader;
17
import java.io.OutputStream;
16 18
import java.util.*;
17 19
18 20
@Slf4j
@ -131,4 +133,48 @@ public class UploadUtil {
131 133
        }
132 134
        return result;
133 135
    }
136
137
    public static void downloadListFolderFiles(Admin admin,String uuid, String uploadPath, String fileName, String cipherKey, HttpServletResponse response) throws Exception {
138
        downloadParamsMap.put("k", uploadPath);
139
        downloadParamsMap.put("cipherKey", cipherKey);
140
        downloadParamsMap.put("srcName", fileName); //选填 可重定义文件名
141
142
//        UserContextModel user = UserContextModel.getCurrentUser();
143
//        if(user != null){
144
//            downloadParamsMap.put("userName",user.getUserName());
145
//        }
146
//        CoreUser user = coreUserService.findById(SessionUtil.getUserId());
147
        if (admin != null) {
148
            downloadParamsMap.put("userName", admin.name);
149
        }
150
        String serverPath = downloadParamsMap.get("serverPath") == null ? "" : downloadParamsMap.get("serverPath").toString();
151
        String fileServiceURL = downloadParamsMap.get("fileServiceURL") == null ? "" : downloadParamsMap.get("fileServiceURL").toString();
152
        Map<String, String> headMap = new HashMap<String, String>() {
153
            {
154
                put("Referer", fileServiceURL);
155
            }
156
        };
157
        OutputStream out = null;
158
        try {
159
            out = response.getOutputStream();
160
            Triple<StatusLine, Header[], String> triple = HttpClientUtil.getInstance().httpDownloadFile(
161
                    serverPath, out,
162
                    headMap, downloadParamsMap);
163
            log.debug(triple.getLeft().toString());
164
            log.debug(Arrays.asList(triple.getMiddle()).toString());
165
            Header[] headerArrs = triple.getMiddle();
166
            for (Header h : headerArrs) {
167
                if ("Content-Length".equals(h.getName())) {
168
                    // 设置输出长度
169
                    response.setHeader("Content-Length", String.valueOf(h.getValue()));
170
                }
171
            }
172
            out.flush();
173
        } catch (Exception e) {
174
            e.printStackTrace();
175
        } finally {
176
            out.close();
177
        }
178
    }
179
134 180
}