From 576e64f01f88f2b3d4cd6bd35f875280f311aa73 Mon Sep 17 00:00:00 2001
From: suerwei <18810552194@163.com>
Date: 星期五, 17 五月 2024 16:43:39 +0800
Subject: [PATCH] 人员管理调整字段,附件上传,附件查看功能

---
 javaweb-plus/javaweb-cms/src/main/java/com/javaweb/geo/service/impl/ProjectDataServiceImpl.java |  138 ++++++++++++++++++++++++++++++++++++++-------
 1 files changed, 116 insertions(+), 22 deletions(-)

diff --git a/javaweb-plus/javaweb-cms/src/main/java/com/javaweb/geo/service/impl/ProjectDataServiceImpl.java b/javaweb-plus/javaweb-cms/src/main/java/com/javaweb/geo/service/impl/ProjectDataServiceImpl.java
index 732af07..ba4ecd0 100644
--- a/javaweb-plus/javaweb-cms/src/main/java/com/javaweb/geo/service/impl/ProjectDataServiceImpl.java
+++ b/javaweb-plus/javaweb-cms/src/main/java/com/javaweb/geo/service/impl/ProjectDataServiceImpl.java
@@ -1,8 +1,17 @@
 package com.javaweb.geo.service.impl;
 
+import java.io.File;
+import java.nio.charset.Charset;
+import java.util.ArrayList;
 import java.util.List;
+
+import cn.hutool.core.io.FileUtil;
+import cn.hutool.core.util.ZipUtil;
+import com.javaweb.common.config.Global;
+import com.javaweb.common.core.domain.AjaxResult;
 import com.javaweb.common.utils.DateUtils;
 import com.javaweb.common.utils.IdGenerate;
+import com.javaweb.common.utils.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import com.javaweb.geo.mapper.ProjectDataMapper;
@@ -10,53 +19,61 @@
 import com.javaweb.geo.service.IProjectDataService;
 import com.javaweb.common.core.text.Convert;
 import org.springframework.util.ObjectUtils;
+import org.springframework.web.multipart.MultipartFile;
+
+import javax.servlet.http.HttpServletRequest;
 
 /**
  * 椤圭洰璧勬枡Service涓氬姟灞傚鐞�
- * 
+ *
  * @author cxy
  * @date 2024-05-16
  */
 @Service
-public class ProjectDataServiceImpl implements IProjectDataService 
-{
+public class ProjectDataServiceImpl implements IProjectDataService {
+
+
+    private static String manUploadPath = "imgupload";
+
+    private static String imgUploadPath = Global.getProfile() + "\\" + manUploadPath + "\\";
+
     @Autowired
     private ProjectDataMapper projectDataMapper;
 
     /**
      * 鏌ヨ椤圭洰璧勬枡
-     * 
+     *
      * @param id 椤圭洰璧勬枡ID
      * @return 椤圭洰璧勬枡
      */
     @Override
-    public ProjectData selectProjectDataById(String id)
-    {
+    public ProjectData selectProjectDataById(String id) {
         return projectDataMapper.selectProjectDataById(id);
     }
 
     /**
      * 鏌ヨ椤圭洰璧勬枡鍒楄〃
-     * 
+     *
      * @param projectData 椤圭洰璧勬枡
      * @return 椤圭洰璧勬枡
      */
     @Override
-    public List<ProjectData> selectProjectDataList(ProjectData projectData)
-    {
+    public List<ProjectData> selectProjectDataList(ProjectData projectData) {
+        if (!ObjectUtils.isEmpty(projectData.getDataType()) && projectData.getDataType().endsWith(",")) {
+            projectData.setDataType(projectData.getDataType().substring(0, 1));
+        }
         return projectDataMapper.selectProjectDataList(projectData);
     }
 
     /**
      * 鏂板椤圭洰璧勬枡
-     * 
+     *
      * @param projectData 椤圭洰璧勬枡
      * @return 缁撴灉
      */
     @Override
-    public int insertProjectData(ProjectData projectData)
-    {
-        if(ObjectUtils.isEmpty(projectData.getId())){
+    public int insertProjectData(ProjectData projectData) {
+        if (ObjectUtils.isEmpty(projectData.getId())) {
             projectData.setId(IdGenerate.nextId());
         }
         projectData.setCreateTime(DateUtils.getNowDate());
@@ -65,38 +82,115 @@
 
     /**
      * 淇敼椤圭洰璧勬枡
-     * 
+     *
      * @param projectData 椤圭洰璧勬枡
      * @return 缁撴灉
      */
     @Override
-    public int updateProjectData(ProjectData projectData)
-    {
+    public int updateProjectData(ProjectData projectData) {
         projectData.setUpdateTime(DateUtils.getNowDate());
         return projectDataMapper.updateProjectData(projectData);
     }
 
     /**
      * 鍒犻櫎椤圭洰璧勬枡瀵硅薄
-     * 
+     *
      * @param ids 闇�瑕佸垹闄ょ殑鏁版嵁ID
      * @return 缁撴灉
      */
     @Override
-    public int deleteProjectDataByIds(String ids)
-    {
+    public int deleteProjectDataByIds(String ids) {
         return projectDataMapper.deleteProjectDataByIds(Convert.toStrArray(ids));
     }
 
     /**
      * 鍒犻櫎椤圭洰璧勬枡淇℃伅
-     * 
+     *
      * @param id 椤圭洰璧勬枡ID
      * @return 缁撴灉
      */
     @Override
-    public int deleteProjectDataById(String id)
-    {
+    public int deleteProjectDataById(String id) {
         return projectDataMapper.deleteProjectDataById(id);
     }
+
+    @Override
+    public AjaxResult uploadZIP(MultipartFile file, HttpServletRequest request) {
+        String uploadPath = Global.getProfile() + "\\";
+
+        String originalFilename = file.getOriginalFilename();
+
+        String fieldname = request.getParameter("fieldname");
+        if (StringUtils.isEmpty(fieldname)) {
+            fieldname = "filename";
+        }
+
+        //鑾峰彇鍚庣紑.zip  淇濆瓨鐨勬枃浠跺悕
+        String substring = originalFilename.substring(originalFilename.lastIndexOf("."));
+        String UID = IdGenerate.nextId();
+        String dFileName = UID + substring;
+
+        File file2 = new File(uploadPath + dFileName);
+        try {
+            file.transferTo(file2);
+        } catch (Exception e) {
+            return AjaxResult.warn("闄勪欢涓婁紶澶辫触锛�");
+        }
+
+        //瑙e帇缂�
+        try {
+            ZipUtil.unzip(file2, Charset.forName("GBK"));
+        } catch (Exception e) {
+            return AjaxResult.warn("闄勪欢瑙e帇缂╁け璐ワ紒");
+        }
+        String moveDir = Global.getProfile() + "\\" + UID + "\\" + originalFilename.replace(substring, "");
+        List<String> movedFiles = moveFile(moveDir);
+        updateFilePath(fieldname, movedFiles);
+
+        FileUtil.del(new File(uploadPath + UID));
+        FileUtil.del(file2);
+        return AjaxResult.success("涓婁紶鎴愬姛");
+    }
+
+    //绉诲姩 鏂囦欢
+    private List<String> moveFile(String moveDir) {
+        List<String> list = new ArrayList<>();
+        File file = new File(moveDir);
+        String detpath = imgUploadPath;
+        if (file.isDirectory()) {
+            File[] files = file.listFiles();
+            int len = files.length;
+            for (int i = 0; i < len; i++) {
+                String filename = files[i].getName();
+                list.add(filename);
+                FileUtil.copy(files[i], new File(detpath + filename), true);
+            }
+        }
+        return list;
+    }
+
+    private void updateFilePath(String filedname, List<String> filesPath) {
+
+        for (String fileName : filesPath) {
+            String substring = fileName.substring(fileName.lastIndexOf("."));
+            String docFileName = fileName.replace(substring, "").trim();
+            ProjectData param = new ProjectData();
+
+            if (filedname.equals("filename")) {
+                param.setName(docFileName);
+            }
+
+            List<ProjectData> list = projectDataMapper.selectProjectDataList(param);
+            if (!ObjectUtils.isEmpty(list)) {
+                for (ProjectData item : list) {
+                    ProjectData entity = new ProjectData();
+                    entity.setId(item.getId());
+                    entity.setDataUrl(manUploadPath + "/" + fileName);
+                    projectDataMapper.updateProjectData(entity);
+                }
+            }
+
+        }
+
+    }
 }

--
Gitblit v1.9.1