Browse Source

上传图片

Signed-off-by: XU <2440975820@qq.com>
XU 10 months ago
parent
commit
a24f72eebe

+ 14 - 0
src/main/java/thyyxxk/webserver/controller/technologyArchives/TechnologyArchivesController.java

@@ -1,5 +1,6 @@
 package thyyxxk.webserver.controller.technologyArchives;
 
+import com.alibaba.fastjson.JSONObject;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.validation.annotation.Validated;
 import org.springframework.web.bind.annotation.GetMapping;
@@ -8,6 +9,7 @@ import org.springframework.web.bind.annotation.RequestBody;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RequestParam;
 import org.springframework.web.bind.annotation.RestController;
+import org.springframework.web.multipart.MultipartFile;
 import thyyxxk.webserver.entity.ResultVo;
 import thyyxxk.webserver.entity.technologyArchives.TechnologyArchives1;
 import thyyxxk.webserver.entity.technologyArchives.TechnologyArchives10;
@@ -75,6 +77,13 @@ public class TechnologyArchivesController {
         return service.saveTechnologyArchives1(first);
     }
 
+    //上传图片
+    @PostMapping("/putCertificateImage")
+    public ResultVo<JSONObject> putCertificateImage(@RequestBody MultipartFile file,
+                                                  @RequestParam(value = "socialNo") String socialNo) {
+        return service.putCertificateImage(file, socialNo);
+    }
+
     @GetMapping("/delTechnologyArchives1ByCode")
     public ResultVo<Map<String, Object>> delTechnologyArchives1ByCode(@RequestParam("socialNo") String socialNo, @RequestParam("getTime") String getTime){
         return service.delTechnologyArchives1ByCode(socialNo, getTime);
@@ -90,6 +99,11 @@ public class TechnologyArchivesController {
         return service.saveTechnologyArchives2(second);
     }
 
+    @PostMapping("/putProImage")
+    public ResultVo<JSONObject> putProImage(@RequestBody MultipartFile file,
+                                                    @RequestParam(value = "socialNo") String socialNo) {
+        return service.putProImage(file, socialNo);
+    }
     @GetMapping("/delTechnologyArchives2ByCode")
     public ResultVo<Map<String, Object>> delTechnologyArchives2ByCode(@RequestParam("socialNo") String socialNo, @RequestParam("no") Integer no){
         return service.delTechnologyArchives2ByCode(socialNo, no);

+ 4 - 0
src/main/java/thyyxxk/webserver/dao/his/technologyArchives/TechnologyArchives1Dao.java

@@ -5,6 +5,8 @@ import org.apache.ibatis.annotations.Mapper;
 import org.apache.ibatis.annotations.Param;
 import org.apache.ibatis.annotations.Select;
 import org.apache.ibatis.annotations.Update;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.multipart.MultipartFile;
 import thyyxxk.webserver.entity.technologyArchives.TechnologyArchives1;
 
 import java.util.List;
@@ -52,4 +54,6 @@ public interface TechnologyArchives1Dao extends BaseMapper<TechnologyArchives1>
     @Update(" delete from technology_archives1 where social_no = #{socialNo} and get_time = #{getTime} ")
     int delTechnologyArchives1ByCode(@Param("socialNo") String socialNo, @Param("getTime") String getTime);
 
+    @Update(" update technology_archives1 set image = #{url} where social_no = #{socialNo} ")
+    int updateCertificateImage(String socialNo, String url);
 }

+ 3 - 0
src/main/java/thyyxxk/webserver/dao/his/technologyArchives/TechnologyArchives2Dao.java

@@ -58,4 +58,7 @@ public interface TechnologyArchives2Dao extends BaseMapper<TechnologyArchives2>
     @Update(" delete from technology_archives2 where social_no = #{socialNo} and no = #{no} ")
     int delTechnologyArchives2ByCode(@Param("socialNo") String socialNo, @Param("no") Integer no);
 
+    @Update(" update technology_archives2 set image = #{url} where social_no = #{socialNo} ")
+    int updateProImage(String socialNo, String url);
+
 }

+ 89 - 6
src/main/java/thyyxxk/webserver/service/technologyArchives/TechnologyArchivesService.java

@@ -1,9 +1,13 @@
 package thyyxxk.webserver.service.technologyArchives;
 
+import cn.hutool.core.io.file.FileNameUtil;
+import com.alibaba.fastjson.JSONObject;
 import lombok.extern.slf4j.Slf4j;
 import org.jetbrains.annotations.NotNull;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Service;
+import org.springframework.web.multipart.MultipartFile;
 import thyyxxk.webserver.config.exception.ExceptionEnum;
 import thyyxxk.webserver.dao.his.technologyArchives.TechnologyArchives10Dao;
 import thyyxxk.webserver.dao.his.technologyArchives.TechnologyArchives11Dao;
@@ -50,12 +54,12 @@ import thyyxxk.webserver.utils.ResultVoUtil;
 import thyyxxk.webserver.utils.StringUtil;
 
 import javax.servlet.http.HttpServletResponse;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Comparator;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.nio.file.StandardCopyOption;
+import java.util.*;
 import java.util.stream.Collectors;
 
 /**
@@ -271,6 +275,47 @@ public class TechnologyArchivesService {
         }
     }
 
+    //职称证书图片
+    @Value("${is-prod}")
+    private boolean isProd;
+
+    public ResultVo<JSONObject> putCertificateImage(MultipartFile file, String socialNo) {
+
+        String uploadDir;
+        if (isProd) {
+            uploadDir = "/home/certificateImage";
+        } else {
+            uploadDir = "E:\\certificateImage";
+        }
+        JSONObject js = new JSONObject();
+
+        String name = file.getOriginalFilename();
+        String fileName = null;
+        if (name != null) {
+            String newName = UUID.randomUUID().toString().replaceAll("-", "");
+            fileName = newName.substring(0,5)+name.substring(name.lastIndexOf("."));
+        }
+        Path uploadPath = Paths.get(uploadDir);
+
+        try {
+            Files.createDirectories(uploadPath);
+            Path filePath = null;
+            if (fileName != null) {
+                filePath = uploadPath.resolve(fileName);
+            }
+            Files.copy(file.getInputStream(), filePath, StandardCopyOption.REPLACE_EXISTING);
+            log.info("文件:{}, socialNo:{}", file.getName(), socialNo);
+            String url = "http://172.16.30.8:8077/certificateImage/" + fileName;
+            int num =firstDao.updateCertificateImage(socialNo,url);
+            js.put("url", url);
+            js.put("name", fileName);
+            return ResultVoUtil.success(js);
+        } catch (IOException e) {
+            log.error("上传错误:{}", e.getMessage());
+            return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "上传错误请重新上传。");
+        }
+    }
+
     /**
      * @Description 根据身份证号,批准时间删除专业技术职称晋升情况
      * @Author hsh
@@ -345,6 +390,44 @@ public class TechnologyArchivesService {
         }
     }
 
+    //其他证书图片
+    public ResultVo<JSONObject> putProImage(MultipartFile file, String socialNo) {
+
+        String uploadDir;
+        if (isProd) {
+            uploadDir = "/home/proImage";
+        } else {
+            uploadDir = "E:\\proImage";
+        }
+        JSONObject js = new JSONObject();
+
+        String name = file.getOriginalFilename();
+        String fileName = null;
+        if (name != null) {
+            String newName = UUID.randomUUID().toString().replaceAll("-", "");
+            fileName = newName.substring(0,5)+name.substring(name.lastIndexOf("."));
+        }
+        Path uploadPath = Paths.get(uploadDir);
+
+        try {
+            Files.createDirectories(uploadPath);
+            Path filePath = null;
+            if (fileName != null) {
+                filePath = uploadPath.resolve(fileName);
+            }
+            Files.copy(file.getInputStream(), filePath, StandardCopyOption.REPLACE_EXISTING);
+            log.info("文件:{}, socialNo:{}", file.getName(), socialNo);
+            String url = "http://172.16.30.8:8077/proImage/" + fileName;
+            int num =secondDao.updateProImage(socialNo,url);
+            js.put("url", url);
+            js.put("name", fileName);
+            return ResultVoUtil.success(js);
+        } catch (IOException e) {
+            log.error("上传错误:{}", e.getMessage());
+            return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "上传错误请重新上传。");
+        }
+    }
+
     /**
      * @Description 根据身份证号,序号删除其它资格证书取得情况
      * @Author hsh