From 7d64716cb0d406f21cde03976fd273bd07fdc06f Mon Sep 17 00:00:00 2001
From: whycxzp <perryhsu@163.com>
Date: 星期二, 28 九月 2021 11:44:28 +0800
Subject: [PATCH] 更新用户-角色-菜单-权限

---
 src/main/java/com/whyc/controller/ProjectManageController.java |  334 ++++++++++++++++++++++++++++++++++---------------------
 1 files changed, 205 insertions(+), 129 deletions(-)

diff --git a/src/main/java/com/whyc/controller/ProjectManageController.java b/src/main/java/com/whyc/controller/ProjectManageController.java
index 0fc6848..90deccf 100644
--- a/src/main/java/com/whyc/controller/ProjectManageController.java
+++ b/src/main/java/com/whyc/controller/ProjectManageController.java
@@ -1,21 +1,28 @@
 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 java.io.File;
-import java.util.Date;
-import java.util.List;
-import java.util.UUID;
+import javax.servlet.http.HttpServletResponse;
+import javax.validation.Valid;
+import java.io.*;
+import java.text.SimpleDateFormat;
+import java.util.*;
 
 
 /**
@@ -27,6 +34,12 @@
 public class ProjectManageController {
 
     @Autowired
+    private MyProps myProps;
+
+    @Autowired
+    private ServerConfig serverConfig;
+
+    @Autowired
     private ProjectProcessManageService service;
 
 
@@ -34,36 +47,23 @@
     private ProjectArchiveManageService archiveManageService;
 
 
-    @GetMapping("all")
-    @ApiOperation(value = "椤圭洰杩囩▼绠$悊-鏌ヨ鎵�鏈�")
-    public Response<List<ProjectManage>> searchAll() {
-
-        return service.searchAll();
-    }
-
-
-    @GetMapping("byCondition")
-    @ApiOperation(notes = "椤圭洰杩囩▼绠$悊",value = "椤圭洰杩囩▼绠$悊-鏉′欢鏌ヨ")
-    public Response<List<ProjectManage>> searchByCondition(@ApiParam(value = "鐢虫姤鏃ユ湡 鏍煎紡 2021/01/28",required = true) @RequestParam Date proCreatedate,
-                                                           @ApiParam(value = "椤圭洰绫诲瀷",required = true)@RequestParam int proSort,
-                                                           @ApiParam(value = "椤圭洰鐘舵��",required = true)@RequestParam int proState,
-                                                           @ApiParam(value = "椤圭洰缂栧彿",required = true)@RequestParam String proNum) {
-        ProjectManage projectManage = new ProjectManage();
-        projectManage.setProCreatedate(proCreatedate);
-        projectManage.setProSort(proSort);
-        projectManage.setProState(proState);
-        projectManage.setProNum(proNum);
-        return service.searchByCondition(projectManage);
+    @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 = "notes涓瓨鏂囦欢鍦板潃鐢� ; 鍒嗛殧 {\n" +
-            "  \"proNum\": S0900033,\n" +
-            "  \"proName\": \"\",\n" +
-            "  \"proNameCode\": \"yyyyMMddHHmmss鏍煎紡瀛楃涓瞈",\n" +
+    @ApiOperation(value = "椤圭洰杩囩▼绠$悊-鏂板缓椤圭洰",notes = "fileList 瀛樻枃浠跺湴鍧� {\n" +
+            "  \"fileList\": [\n" +
+            "    \n" +
+            "  ],\n" +
+            "  \"proNum\": \"S0900033\",\n" +
+            "  \"proName\": \"鑸拌埞鐢垫皵鍔ㄥ姏璇曢獙\",\n" +
             "  \"proSort\": 0,\n" +
             "  \"proAdmin\": \"寮犱笁\",\n" +
-            "  \"proTel\": 13800003131,\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" +
@@ -72,52 +72,126 @@
             "  \"proFundingSource\": \"缁忚垂鏉ユ簮\",\n" +
             "  \"proContent\": \" \",\n" +
             "  \"proState\": 0,\n" +
-            "  \"note\": \"鎷兼帴澶氫釜鏂囦欢鍦板潃\"\n" +
+            "  \"proProgress\": 0\n" +
             "}")
-    public Response add(@RequestBody ProjectManage projectManage) {
-
+    public Response add(@RequestBody @Valid ProjectManage projectManage) {
         Response response = service.add(projectManage);
         return response;
     }
 
+
     /**
      * 鏂囦欢瀛樺偍鍚庡湴鍧�鏇存柊鍒板搴旈」鐩紪鍙风殑鍦板潃锛屼竴涓」鐩搴斿涓枃浠� db_experiment.tb_project_archive_manage
      * 鏄惁闇�瑕佸皢word杞琾df/棰勮鏂囦欢pdf
+     *
      * @param file
      * @return
      */
-    @PostMapping("upload")
-    @ApiOperation(notes = "杩斿洖鏂囦欢鍦板潃锛岀‘璁ゆ椂鎻愪氦淇濆瓨鍒板瓧娈�",value = "鏂囨。鏉愭枡娣诲姞(閫夋嫨鏂囦欢)")
-    public Response upload(@RequestParam("file") MultipartFile file) {
-        // 鑾峰彇鍘熷鍚嶅瓧
-        String fileName = file.getOriginalFilename();
-        // 鑾峰彇鍚庣紑鍚�
-        // String suffixName = fileName.substring(fileName.lastIndexOf("."));
-        // 鏂囦欢淇濆瓨璺緞銆佸悗鏈熻�冭檻鎸夋棩鏈熸垨鑰呮湀浠藉缓dir
-        String filePath = "c:/upload/";
-        // 鏂囦欢閲嶅懡鍚嶏紝闃叉閲嶅,棰勮鏃堕渶瑕佹樉绀哄師鏂囦欢鍚� _ 鍒囧壊
-        fileName = filePath + UUID.randomUUID() + "_" + fileName;
-        // 鏂囦欢瀵硅薄
-        File dest = new File(fileName);
-        // 鍒ゆ柇璺緞鏄惁瀛樺湪锛屽鏋滀笉瀛樺湪鍒欏垱寤�
-        if (!dest.getParentFile().exists()) {
-            dest.getParentFile().mkdirs();
-        }
-        try {
-            // 淇濆瓨鍒版湇鍔″櫒涓�
-            file.transferTo(dest);
-        } catch (Exception e) {
-            e.printStackTrace();
-            return new Response().setCode(0);
-        }
+    @PostMapping("/uploads")
+    @ApiOperation(notes = "杩斿洖鏂囦欢鍦板潃锛岀‘璁ゆ椂鎻愪氦淇濆瓨鍒板瓧娈�", value = "椤圭洰杩囩▼绠$悊-鏂囨。鏉愭枡娣诲姞(澶氶��)")
+    public Response uploads(MultipartFile[] file) throws IOException {
         Response<Object> response = new Response<>();
-        response.setMsg(1, fileName);
-        return 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 = "椤圭洰绠$悊-宸辩‘璁ら樁娈垫煡璇�")
+    @ApiOperation(notes = "", value = "椤圭洰杩囩▼绠$悊-宸辩‘璁�/鏈‘璁ら樁娈垫煡璇�")
     public Response<Object> searchManageStateByCondition(@ApiParam(value = "椤圭洰缂栧彿", required = true) @RequestParam String proNum,
                                                          @ApiParam(value = "椤圭洰鍚嶇О浠g爜", required = true) @RequestParam String proNameCode) {
         ProjectManage projectManage = new ProjectManage();
@@ -128,26 +202,32 @@
 
 
     /**
-     * 椤圭洰杩涘害纭 pro_progress
+     * 椤圭洰杩涘害纭 pro_progress,鏈綊妗e彲浠ヤ慨鏀规洿鏂帮紝褰掓。鍚庝笉鑳戒慨鏀�
      * @return
      */
     @PutMapping("updateManageState")
-    @ApiOperation(notes = "椤圭洰绠$悊-宸辩‘璁ら樁娈�",value = "椤圭洰绠$悊-宸辩‘璁ら樁娈垫洿鏂�")
-    public Response updateManageState(@ApiParam(value = "椤圭洰缂栧彿", required = true) @RequestParam String proNum,
-                                      @ApiParam(value = "椤圭洰鍚嶇О浠g爜", required = true) @RequestParam String proNameCode,
-                                      @ApiParam(value = "椤圭洰杩涘害纭0-6",required = true)@RequestParam int proProgress,
-                                      @ApiParam(value = "鏂囨。涓婁紶淇濆瓨鍦板潃(濡傛灉鏃犱紶绌哄瓧绗︿覆)",required = true)@RequestParam String proFilePath) {
-        ProjectManage projectManage = new ProjectManage();
-        projectManage.setProNum(proNum);
-        projectManage.setProNameCode(proNameCode);
-        projectManage.setProProgress(proProgress);
-        projectManage.setNote(proFilePath);
+    @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 = "椤圭洰鍚嶇О浠g爜", required = true) @RequestParam String proNameCode) {
+        ProjectManage projectManage = new ProjectManage();
+        projectManage.setProNum(proNum);
+        projectManage.setProNameCode(proNameCode);
+        projectManage.setProProgress(6);
+        return service.updateProjectProgress(projectManage);
+    }
 
-    @PutMapping("searchDoc")
-    @ApiOperation(notes = "椤圭洰绠$悊-宸辩‘璁ら樁娈�",value = "鏂囨。鏉愭枡鏌ヨ")
+
+
+
+    @GetMapping("searchDoc")
+    @ApiOperation(notes = "椤圭洰杩囩▼绠$悊-椤圭洰绠$悊",value = "椤圭洰杩囩▼绠$悊-鏂囨。鏉愭枡鏌ヨ")
     public  Response searchDocumentation(@ApiParam(value = "椤圭洰缂栧彿", required = true) @RequestParam String proNum,
                                          @ApiParam(value = "椤圭洰鍚嶇О浠g爜", required = true) @RequestParam String proNameCode){
         ProjectArchiveManage projectArchiveManage = new ProjectArchiveManage();
@@ -157,8 +237,8 @@
 
     }
 
-    @PutMapping("delDoc")
-    @ApiOperation(notes = "椤圭洰绠$悊-宸辩‘璁ら樁娈�",value = "鏂囨。鏉愭枡鍒犻櫎")
+    @DeleteMapping("delDoc")
+    @ApiOperation(notes = "椤圭洰杩囩▼绠$悊-椤圭洰绠$悊",value = "椤圭洰杩囩▼绠$悊-鏂囨。鏉愭枡鍒犻櫎")
     public  Response delDocumentation(@ApiParam(value = "椤圭洰缂栧彿", required = true) @RequestParam String proNum,
                                       @ApiParam(value = "椤圭洰鍚嶇О浠g爜", required = true) @RequestParam String proNameCode,
                                       @ApiParam(value = "鏂囨。璺緞", required = true) @RequestParam String proFilePath){
@@ -169,71 +249,67 @@
         return  archiveManageService.delDocumentation(projectArchiveManage);
     }
 
-    @GetMapping("archiveAll")
-    @ApiOperation(value = "椤圭洰褰掓。绠$悊-鏌ヨ鎵�鏈�")
-    public Response<List<ProjectManage>> searchArchiveAll() {
 
-        return archiveManageService.searchAll();
-    }
-    @GetMapping("archiveByCondition")
-    @ApiOperation(value = "椤圭洰褰掓。绠$悊-鏉′欢鏌ヨ")
-    public Response searchArchiveByCondition(@ApiParam(value = "寮�濮嬫棩鏈� 鏍煎紡 2021/01/28",required = true) @RequestParam Date gainDate,
-                                             @ApiParam(value = "褰掓。鏃ユ湡",required = true)@RequestParam Date proArchiveDate,
-                                             @ApiParam(value = "椤圭洰绫诲瀷",required = true)@RequestParam int proSort,
-                                             @ApiParam(value = "椤圭洰缂栧彿",required = true)@RequestParam String proNum) {
+    @PostMapping("archiveByCondition")
+    @ApiOperation(value = "椤圭洰褰掓。绠$悊-鏌ヨ鍒嗛〉-鏍规嵁绛涢�夋潯浠�")
+    public Response<PageInfo<ProjectManage>> searchArchiveByCondition(@RequestParam int pageNum, @RequestParam int pageSize, @RequestBody ProjectManage projectManage) {
 
-        ProjectArchiveManage pam = new ProjectArchiveManage();
-        pam.setGainDate(gainDate);
-        pam.setProArchiveDate(proArchiveDate);
-        pam.setProSort(proSort);
-        pam.setProNum(proNum);
-
-        return archiveManageService.searchArchiveByCondition(pam);
+        return archiveManageService.searchArchiveByCondition(pageNum,pageSize,projectManage);
     }
 
+    @GetMapping("archiveProjectInfo")
+    @ApiOperation(value = "椤圭洰褰掓。绠$悊-椤圭洰姒傚喌淇℃伅")
+    public Response searchArchiveProjectInfo(@ApiParam(value = "椤圭洰鍚嶇О浠g爜", 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);
+    }
 
     /**
-     * 鏂囦欢涓婁紶
-     * achievement_name 鎴愭灉绫诲瀷
+     * @param proNameCode
+     * @param proNum
+     * @return 鏂囨。鏍煎紡銆佹枃妗e悕绉般�佸綊妗f棩鏈熴�佷笅杞借矾寰�
      */
-/*
-    @RequestMapping("/upload")
-    public Response upload(MultipartFile file) {
-        try {
-            if (file != null) {
-                File parentFile = createParentFile();
-                String fileName = file.getOriginalFilename();
-                String suffix = fileName.substring(fileName.lastIndexOf("."));
-                String uuid = IdUtil.simpleUUID();
-                fileName = uuid + suffix;
-                File imageFile = new File(parentFile, fileName);
-                FileUtil.writeFromStream(file.getInputStream(), imageFile);
-                */
-/**
-                 * 骞存湀鏃ョ洰褰�
-                 *//*
+    @GetMapping("archiveDocManager")
+    @ApiOperation(value = "椤圭洰褰掓。绠$悊-鏂囨。绠$悊")
+    public Response searchProjectDocByCondition(@ApiParam(value = "椤圭洰鍚嶇О浠g爜", required = true) @RequestParam String proNameCode,
+                                                                 @ApiParam(value = "椤圭洰缂栧彿", required = true) @RequestParam String proNum) {
+        ProjectArchiveManage pam = new ProjectArchiveManage();
+        pam.setProNum(proNum);
+        pam.setProNameCode(proNameCode);
 
-                String fileDay = DateUtil.thisYear() + "/" + (DateUtil.thisMonth() + 1) + "/"
-                        + DateUtil.thisDayOfMonth();
-                String imagePath = SystemConstant.FILE + "/document/" + fileDay + "/" + fileName;
-                */
-/**
-                 * 瀹炴椂杞崲
-                 *//*
-
-                File toFile = new File(parentFile, uuid + ".pdf");
-                documentConverter.convert(imageFile).to(toFile).execute();
-                return Result.ok(imagePath);
-            } else {
-                return Result.error();
-            }
-        } catch (Exception e) {
-            LOGGER.error("杞崲寮傚父{}",e);
-            return Result.error();
-        }
+        return archiveManageService.searchProjectDocByCondition(pam);
     }
 
-*/
+    /**
+     * @param proNameCode
+     * @return 瀹為獙鍚嶇О銆佽瘯楠屾棩鏈熴�佺粨璁哄瓧娈� etc
+     */
+    @GetMapping("archiveExperimentData")
+    @ApiOperation(notes = "TODO 鏂囦欢鏍煎紡鍜屼笅杞藉湴鍧�", value = "椤圭洰褰掓。绠$悊-璇曢獙鏁版嵁")
+    public Response searchArchiveExperimentData(@ApiParam(value = "椤圭洰鍚嶇О浠g爜", required = true) @RequestParam String proNameCode) {
+    //TODO fileName file
+        return archiveManageService.searchArchiveExperimentData(proNameCode);
+    }
+
+    @GetMapping("archiveTechnologicalAchievements")
+    @ApiOperation(notes = "(鎿嶄綔TODO)", value = "椤圭洰褰掓。绠$悊-绉戞妧鎴愭灉")
+    public Response searchArchiveTechnologicalAchievements(@ApiParam(value = "椤圭洰鍚嶇О浠g爜", 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);
+    }
+
+
+
+
+
 
 
 }

--
Gitblit v1.9.1