From b9b712a7701eb83c7dbd8367c534d4c880503adb Mon Sep 17 00:00:00 2001
From: zmk <496160012@qq.com>
Date: 星期六, 18 五月 2024 16:51:19 +0800
Subject: [PATCH] 提交代码

---
 javaweb-plus/javaweb-cms/src/main/java/com/javaweb/geo/service/impl/ProjectDataServiceImpl.java |  111 ++++++++++++++++++++++++++++++++-----------------------
 1 files changed, 65 insertions(+), 46 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 ba4ecd0..030592f 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
@@ -12,12 +12,17 @@
 import com.javaweb.common.utils.DateUtils;
 import com.javaweb.common.utils.IdGenerate;
 import com.javaweb.common.utils.StringUtils;
+import com.javaweb.geo.domain.Hole;
+import com.javaweb.geo.domain.HoleMedia;
+import com.javaweb.geo.mapper.HoleMapper;
+import com.javaweb.geo.mapper.HoleMediaMapper;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import com.javaweb.geo.mapper.ProjectDataMapper;
 import com.javaweb.geo.domain.ProjectData;
 import com.javaweb.geo.service.IProjectDataService;
 import com.javaweb.common.core.text.Convert;
+import org.springframework.transaction.annotation.Transactional;
 import org.springframework.util.ObjectUtils;
 import org.springframework.web.multipart.MultipartFile;
 
@@ -33,12 +38,23 @@
 public class ProjectDataServiceImpl implements IProjectDataService {
 
 
-    private static String manUploadPath = "imgupload";
+    private static String zipfile = "zipfile";
+    private static String zipfile2 = "zipfile2";
 
-    private static String imgUploadPath = Global.getProfile() + "\\" + manUploadPath + "\\";
+    //zip 鍘熷鏂囦欢
+    private static String ZIPUploadPath = Global.getProfile() + "\\" + zipfile + "\\";
+
+    //瑙e帇鏂囦欢
+    private static String ZIPUploadPath2 = Global.getProfile() + "\\" + zipfile2 + "\\";
 
     @Autowired
     private ProjectDataMapper projectDataMapper;
+    @Autowired
+    private HoleMapper holeMapper;
+
+    @Autowired
+    private HoleMediaMapper mediaMapper;
+
 
     /**
      * 鏌ヨ椤圭洰璧勬枡
@@ -116,21 +132,17 @@
 
     @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";
-        }
+        //浼犲叆鐨勯捇瀛旂殑id
+        String projectDataId = request.getParameter("projectDataId");
 
         //鑾峰彇鍚庣紑.zip  淇濆瓨鐨勬枃浠跺悕
         String substring = originalFilename.substring(originalFilename.lastIndexOf("."));
         String UID = IdGenerate.nextId();
         String dFileName = UID + substring;
 
-        File file2 = new File(uploadPath + dFileName);
+        File file2 = new File(ZIPUploadPath + dFileName);
         try {
             file.transferTo(file2);
         } catch (Exception e) {
@@ -143,53 +155,60 @@
         } 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);
+        //绉诲姩鍒皕ipfile2  瀛樺偍瑙e帇瀹屾瘯鐨勬枃浠�
+        String moveDir = ZIPUploadPath + UID;
+        moveFile(moveDir);
+
+        //鏇存柊鏁版嵁搴�
+        updateFilePath(projectDataId, ZIPUploadPath2 + UID +"\\" + originalFilename.replace(substring, "") );
+
+        ProjectData projectData = new ProjectData();
+
+        //鏇存柊  projectData  url
+        String dataUrl = zipfile + "/" + UID +".zip";
+        projectData.setDataUrl(dataUrl);
+        projectData.setId(projectDataId);
+        projectDataMapper.updateProjectData(projectData);
+
+        FileUtil.del(new File(ZIPUploadPath + UID));
+
         return AjaxResult.success("涓婁紶鎴愬姛");
     }
 
     //绉诲姩 鏂囦欢
-    private List<String> moveFile(String moveDir) {
-        List<String> list = new ArrayList<>();
+    private void moveFile(String moveDir) {
         File file = new File(moveDir);
-        String detpath = imgUploadPath;
-        if (file.isDirectory()) {
-            File[] files = file.listFiles();
+        File dest = new File(ZIPUploadPath2);
+        FileUtil.move(file,dest,true);
+    }
+
+
+    @Transactional(rollbackFor = Exception.class)
+    public void updateFilePath(String projectDataId, String dirpath) {
+
+        ProjectData projectData = projectDataMapper.selectProjectDataById(projectDataId);
+        String projectId= projectData.getProjectId();
+
+        File fileDir = new File(dirpath);
+
+        if (fileDir.isDirectory()) {
+            File[] files = fileDir.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);
+                String filepath = files[i].getPath();
+                String url = filepath.replace(Global.getProfile(),"").replace("\\","/");
+
+                HoleMedia media = new HoleMedia();
+                media.setIds(IdGenerate.nextId());
+                media.setRecordId(projectDataId);
+                media.setProjectId(projectId);
+                media.setName(filename);
+                media.setInternetPath(url);
+                media.setCreateTime(DateUtils.getNowDate());
+                mediaMapper.insertHoleMedia(media);
             }
-        }
-        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