whyczh
2021-04-07 9f83bdaebfd57892bc48857c286780a01efeb581
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
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
package com.whyc.controller;
 
import com.github.pagehelper.PageInfo;
import com.whyc.config.MyProps;
import com.whyc.config.ServerConfig;
import com.whyc.dto.Response;
import com.whyc.pojo.ProjectArchiveManage;
import com.whyc.pojo.ProjectManage;
import com.whyc.service.ProjectArchiveManageService;
import com.whyc.service.ProjectProcessManageService;
import com.whyc.util.FileUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.apache.ibatis.annotations.Delete;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
 
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.io.*;
import java.text.SimpleDateFormat;
import java.util.*;
 
 
/**
 * 项目管理/项目归档管理、项目过程管理
 */
@RestController
@RequestMapping("projectManage")
@Api(tags = "项目管理")
public class ProjectManageController {
 
    @Autowired
    private MyProps myProps;
 
    @Autowired
    private ServerConfig serverConfig;
 
    @Autowired
    private ProjectProcessManageService service;
 
 
    @Autowired
    private ProjectArchiveManageService archiveManageService;
 
 
    @PostMapping("progressByCondition")
    @ApiOperation(notes = "项目过程管理", value = "项目过程管理-查询分页-根据筛选条件")
    public Response<PageInfo<ProjectManage>> searchByCondition(@RequestParam int pageNum, @RequestParam int pageSize, @RequestBody ProjectManage projectManage) {
        return service.searchByCondition(pageNum, pageSize, projectManage);
    }
 
    @PostMapping("add")
    @ApiOperation(value = "项目过程管理-新建项目",notes = "fileList 存文件地址 {\n" +
            "  \"fileList\": [\n" +
            "    \n" +
            "  ],\n" +
            "  \"proNum\": \"S0900033\",\n" +
            "  \"proName\": \"舰船电气动力试验\",\n" +
            "  \"proSort\": 0,\n" +
            "  \"proAdmin\": \"张三\",\n" +
            "  \"proDepartment\": \"xxxx\",\n" +
            "  \"proTel\": \"13800003131\",\n" +
            "  \"proCreatedate\": \"2021-03-27 08:18:27\",\n" +
            "  \"proExecutionDate\": \"2021-03-27 08:18:27\",\n" +
            "  \"proExecutionDate1\": \"2021-03-27 08:18:27\",\n" +
            "  \"proPerson\": \"参与人员\",\n" +
            "  \"proFunding\": 0,\n" +
            "  \"proFundingSource\": \"经费来源\",\n" +
            "  \"proContent\": \" \",\n" +
            "  \"proState\": 0,\n" +
            "  \"proProgress\": 0\n" +
            "}")
    public Response add(@RequestBody @Valid ProjectManage projectManage) {
        Response response = service.add(projectManage);
        return response;
    }
 
 
    /**
     * 文件存储后地址更新到对应项目编号的地址,一个项目对应多个文件 db_experiment.tb_project_archive_manage
     * 是否需要将word转pdf/预览文件pdf
     *
     * @param file
     * @return
     */
    @PostMapping("/uploads")
    @ApiOperation(notes = "返回文件地址,确认时提交保存到字段", value = "项目过程管理-文档材料添加(多选)")
    public Response uploads(MultipartFile[] file) throws IOException {
        Response<Object> response = new Response<>();
        if (file.length == 0) {
            return response.setMsg(0, "请选择要上传的文件");
        }
 
        ArrayList<Object> list = new ArrayList<>();
//            String filePath = myProps.getFilePath();
        String uploadPath = FileUtils.getProjectPath();
//        System.out.println("uploadPath = " + uploadPath);
        for (MultipartFile multipartFile : file) {
            if (multipartFile.isEmpty()) {
                return response.setMsg(0, "请选择要上传的文件");
            }
            byte[] fileBytes = multipartFile.getBytes();
            //取得当前上传文件的文件名称
            String originalFilename = multipartFile.getOriginalFilename();
            //生成文件名
            String fileName = UUID.randomUUID() + "_" + originalFilename;
 
            HashMap<Object, Object> map = new HashMap<>();
            map.put("name", originalFilename);
            String url = serverConfig.getUrl();
            map.put("url", url + "/uploadFile/" + fileName);
            try {
                FileUtils.uploadFile(fileBytes, uploadPath, fileName);
            } catch (IOException e) {
                e.printStackTrace();
                return response.setMsg(0, "上传失败");
            }
            list.add(map);
 
        }
        response.setData(list);
        return response.setMsg(1, "上传成功");
    }
 
 
    @GetMapping("/download")
    @ApiOperation(notes = "需要在地址栏测试 http://localhost:8090/projectManage/download?fileName=申请书.pdf",value = "项目过程管理-文档材料下载")
    public String download(HttpServletResponse response, @ApiParam(value = "文件路径",required = true)@RequestParam String filePath) {
        String fileName = "";
        if (filePath.length() > 10&&filePath.contains("/")) {   //IP地址+文件名
            int lastIndexOf = filePath.lastIndexOf("/");
            fileName = filePath.substring(lastIndexOf);
        } else {
            return "filePath is Error";
        }
 
        String projectPath = FileUtils.getProjectPath();
        File file = new File( projectPath+fileName);
        if (file.exists()) {
            try {
                fileName= new String(fileName.getBytes("gbk"), "ISO8859-1");
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
            }
            response.setContentType("application/force-download");
            // 设置强制下载不打开
            response.addHeader("Content-Disposition", "attachment;fileName=" + fileName);
            byte[] buffer = new byte[1024];
            FileInputStream fis = null;
            BufferedInputStream bis = null;
            try {
                fis = new FileInputStream(file);
                bis = new BufferedInputStream(fis);
                OutputStream outputStream = response.getOutputStream();
                int i = bis.read(buffer);
                while (i != -1) {
                    outputStream.write(buffer, 0, i);
                    i = bis.read(buffer);
                }
//               return result.setMsg(1,"下载成功");
               return "downloadSuccessful";
            } catch (Exception e) {
                e.printStackTrace();
//                return result.setMsg(0,"下载失败");
                return "downloadFailed";
            } finally {
                if (bis != null) {
                    try {
                        bis.close();
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                }
                if (fis != null) {
                    try {
                        fis.close();
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                }
            }
        }else{
            return "fileDoesNotExist";
        }
    }
 
 
 
    @GetMapping("managesState")
    @ApiOperation(notes = "", value = "项目过程管理-己确认/未确认阶段查询")
    public Response<Object> searchManageStateByCondition(@ApiParam(value = "项目编号", required = true) @RequestParam String proNum,
                                                         @ApiParam(value = "项目名称代码", required = true) @RequestParam String proNameCode) {
        ProjectManage projectManage = new ProjectManage();
        projectManage.setProNum(proNum);
        projectManage.setProNameCode(proNameCode);
        return service.searchManageStateByCondition(projectManage);
    }
 
 
    /**
     * 项目进度确认 pro_progress,未归档可以修改更新,归档后不能修改
     * @return
     */
    @PutMapping("updateManageState")
    @ApiOperation(notes = "项目进度确认1-6 对应 立项-审批-研究-结题-验收-归档",value = "项目过程管理-未确认阶段更新")
    public Response updateManageState(@RequestBody ProjectManage projectManage) {
 
        return service.updateManageState(projectManage);
    }
 
    @PutMapping("updateArchive")
    @ApiOperation(notes = "",value = "项目过程管理-归档")
    public Response updateArchive(@ApiParam(value = "项目编号", required = true) @RequestParam String proNum,
                                  @ApiParam(value = "项目名称代码", required = true) @RequestParam String proNameCode) {
        ProjectManage projectManage = new ProjectManage();
        projectManage.setProNum(proNum);
        projectManage.setProNameCode(proNameCode);
        projectManage.setProProgress(6);
        return service.updateProjectProgress(projectManage);
    }
 
 
 
 
    @GetMapping("searchDoc")
    @ApiOperation(notes = "项目过程管理-项目管理",value = "项目过程管理-文档材料查询")
    public  Response searchDocumentation(@ApiParam(value = "项目编号", required = true) @RequestParam String proNum,
                                         @ApiParam(value = "项目名称代码", required = true) @RequestParam String proNameCode){
        ProjectArchiveManage projectArchiveManage = new ProjectArchiveManage();
        projectArchiveManage.setProNum(proNum);
        projectArchiveManage.setProNameCode(proNameCode);
        return  archiveManageService.searchDocumentation(projectArchiveManage);
 
    }
 
    @DeleteMapping("delDoc")
    @ApiOperation(notes = "项目过程管理-项目管理",value = "项目过程管理-文档材料删除")
    public  Response delDocumentation(@ApiParam(value = "项目编号", required = true) @RequestParam String proNum,
                                      @ApiParam(value = "项目名称代码", required = true) @RequestParam String proNameCode,
                                      @ApiParam(value = "文档路径", required = true) @RequestParam String proFilePath){
        ProjectArchiveManage projectArchiveManage = new ProjectArchiveManage();
        projectArchiveManage.setProNum(proNum);
        projectArchiveManage.setProNameCode(proNameCode);
        projectArchiveManage.setProFilePath(proFilePath);
        return  archiveManageService.delDocumentation(projectArchiveManage);
    }
 
 
    @PostMapping("archiveByCondition")
    @ApiOperation(value = "项目归档管理-查询分页-根据筛选条件")
    public Response<PageInfo<ProjectManage>> searchArchiveByCondition(@RequestParam int pageNum, @RequestParam int pageSize, @RequestBody ProjectManage projectManage) {
 
        return archiveManageService.searchArchiveByCondition(pageNum,pageSize,projectManage);
    }
 
    @GetMapping("archiveProjectInfo")
    @ApiOperation(value = "项目归档管理-项目概况信息")
    public Response searchArchiveProjectInfo(@ApiParam(value = "项目名称代码", required = true) @RequestParam String proNameCode,
                                             @ApiParam(value = "项目编号", required = true) @RequestParam String proNum) {
 
        ProjectManage pm = new ProjectManage();
        pm.setProNameCode(proNameCode);
        pm.setProNum(proNum);
 
        return archiveManageService.searchArchiveProjectInfo(pm);
    }
 
    /**
     * @param proNameCode
     * @param proNum
     * @return 文档格式、文档名称、归档日期、下载路径
     */
    @GetMapping("archiveDocManager")
    @ApiOperation(value = "项目归档管理-文档管理")
    public Response searchProjectDocByCondition(@ApiParam(value = "项目名称代码", required = true) @RequestParam String proNameCode,
                                                                 @ApiParam(value = "项目编号", required = true) @RequestParam String proNum) {
        ProjectArchiveManage pam = new ProjectArchiveManage();
        pam.setProNum(proNum);
        pam.setProNameCode(proNameCode);
 
        return archiveManageService.searchProjectDocByCondition(pam);
    }
 
    /**
     * @param proNameCode
     * @return 实验名称、试验日期、结论字段 etc
     */
    @GetMapping("archiveExperimentData")
    @ApiOperation(notes = "TODO 文件格式和下载地址", value = "项目归档管理-试验数据")
    public Response searchArchiveExperimentData(@ApiParam(value = "项目名称代码", required = true) @RequestParam String proNameCode) {
    //TODO fileName file
        return archiveManageService.searchArchiveExperimentData(proNameCode);
    }
 
    @GetMapping("archiveTechnologicalAchievements")
    @ApiOperation(notes = "(操作TODO)", value = "项目归档管理-科技成果")
    public Response searchArchiveTechnologicalAchievements(@ApiParam(value = "项目名称代码", required = true) @RequestParam String proNameCode,
                                                           @ApiParam(value = "项目编号", required = true) @RequestParam String proNum) {
        ProjectArchiveManage pam = new ProjectArchiveManage();
        pam.setProNum(proNum);
        pam.setProNameCode(proNameCode);
        return archiveManageService.searchArchiveTechnologicalAchievements(pam);
    }
 
 
 
 
 
 
 
}