From 8722d2bb39c6c0697647e77a879d14b28d3ef0f5 Mon Sep 17 00:00:00 2001 From: zmk <496160012@qq.com> Date: 星期五, 17 五月 2024 19:16:36 +0800 Subject: [PATCH] Merge branch 'master' of ssh://117.78.1.188:29418/dkyChenJiang --- javaweb-plus/javaweb-cms/src/main/java/com/javaweb/geo/service/impl/ProjectDataServiceImpl.java | 101 +++++++++++++++++++++++++++++++++++++++++++++++++- 1 files changed, 99 insertions(+), 2 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 e5a66b5..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,9 +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; @@ -11,6 +19,9 @@ 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涓氬姟灞傚鐞� @@ -20,6 +31,12 @@ */ @Service public class ProjectDataServiceImpl implements IProjectDataService { + + + private static String manUploadPath = "imgupload"; + + private static String imgUploadPath = Global.getProfile() + "\\" + manUploadPath + "\\"; + @Autowired private ProjectDataMapper projectDataMapper; @@ -42,8 +59,8 @@ */ @Override public List<ProjectData> selectProjectDataList(ProjectData projectData) { - if (!ObjectUtils.isEmpty(projectData.getDataType()) && projectData.getDataType().endsWith(",")){ - projectData.setDataType(projectData.getDataType().substring(0,1)); + if (!ObjectUtils.isEmpty(projectData.getDataType()) && projectData.getDataType().endsWith(",")) { + projectData.setDataType(projectData.getDataType().substring(0, 1)); } return projectDataMapper.selectProjectDataList(projectData); } @@ -96,4 +113,84 @@ 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