|  |  | 
 |  |  | package com.javaweb.geo.service.impl; | 
 |  |  |  | 
 |  |  | import java.io.File; | 
 |  |  | import java.io.IOException; | 
 |  |  | import java.nio.charset.Charset; | 
 |  |  | import java.util.ArrayList; | 
 |  |  | import java.util.List; | 
 |  |  |  | 
 |  |  | import cn.hutool.core.io.FileUtil; | 
 |  |  | import cn.hutool.core.util.ObjectUtil; | 
 |  |  | import cn.hutool.core.util.ZipUtil; | 
 |  |  | import com.javaweb.common.config.Global; | 
 |  |  | import com.javaweb.common.core.domain.AjaxResult; | 
 |  |  | import com.javaweb.common.exception.BusinessException; | 
 |  |  | import com.javaweb.common.utils.DateUtils; | 
 |  |  | import com.javaweb.common.utils.IdGenerate; | 
 |  |  | import com.javaweb.common.utils.StringUtils; | 
 |  |  | 
 |  |  |  | 
 |  |  |     //解压文件 | 
 |  |  |     private static String ZIPUploadPath2 = Global.getProfile() + "\\" + zipfile2 + "\\"; | 
 |  |  |  | 
 |  |  |     //单文件存储路径 | 
 |  |  |     private static String ZIPUploadPath2SingleFile = Global.getProfile() + "\\" + zipfile2 + "\\img\\"; | 
 |  |  |  | 
 |  |  |     @Autowired | 
 |  |  |     private ProjectDataMapper projectDataMapper; | 
 |  |  | 
 |  |  |         return projectDataMapper.deleteProjectDataById(id); | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |  | 
 |  |  |  | 
 |  |  |     @Override | 
 |  |  |     public AjaxResult uploadZIP(MultipartFile file, HttpServletRequest request) { | 
 |  |  |     public AjaxResult uploadZIP(MultipartFile file, HttpServletRequest request)  { | 
 |  |  |  | 
 |  |  |         String originalFilename = file.getOriginalFilename(); | 
 |  |  |  | 
 |  |  |         //传入的钻孔的id | 
 |  |  |         String projectDataId = request.getParameter("projectDataId"); | 
 |  |  |  | 
 |  |  |         //上传单文件 | 
 |  |  |         if(ObjectUtil.isNotEmpty(originalFilename) && !originalFilename.endsWith(".zip")){ | 
 |  |  |             uploadSingleFile(file,projectDataId); | 
 |  |  |             return AjaxResult.success("上传成功"); | 
 |  |  |         } | 
 |  |  |         //上传ZIP文件 | 
 |  |  |  | 
 |  |  |         //获取后缀.zip  保存的文件名 | 
 |  |  |         String substring = originalFilename.substring(originalFilename.lastIndexOf(".")); | 
 |  |  | 
 |  |  |         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); | 
 |  |  |         updateFilePath(projectDataId, ZIPUploadPath2 + UID ); | 
 |  |  |  | 
 |  |  |         FileUtil.del(new File(ZIPUploadPath + UID)); | 
 |  |  |  | 
 |  |  |         return AjaxResult.success("上传成功"); | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     //上传单文件 | 
 |  |  |     private void uploadSingleFile(MultipartFile file,String projectDataId) { | 
 |  |  |  | 
 |  |  |         ProjectData projectData = projectDataMapper.selectProjectDataById(projectDataId); | 
 |  |  |         String projectId= projectData.getProjectId(); | 
 |  |  |  | 
 |  |  |         String originalFilename= file.getOriginalFilename(); | 
 |  |  |         //获取后缀  保存的文件名 | 
 |  |  |         String substring = originalFilename.substring(originalFilename.lastIndexOf(".")); | 
 |  |  |         String UID = IdGenerate.nextId(); | 
 |  |  |         String dFileName = UID + substring; | 
 |  |  |  | 
 |  |  |         String filepath = ZIPUploadPath2SingleFile + dFileName; | 
 |  |  |  | 
 |  |  |         File destFile = new File(filepath); | 
 |  |  |  | 
 |  |  |         try{ | 
 |  |  |             file.transferTo(destFile); | 
 |  |  |         }catch (Exception e){ | 
 |  |  |             throw new BusinessException("保存失败!",e); | 
 |  |  |         } | 
 |  |  |  | 
 |  |  |         String url = filepath.replace(Global.getProfile(),"").replace("\\","/"); | 
 |  |  |  | 
 |  |  |         HoleMedia media = new HoleMedia(); | 
 |  |  |         media.setIds(IdGenerate.nextId()); | 
 |  |  |         media.setRecordId(projectDataId); | 
 |  |  |         media.setProjectId(projectId); | 
 |  |  |         media.setName(originalFilename); | 
 |  |  |         media.setInternetPath(url); | 
 |  |  |         media.setCreateTime(DateUtils.getNowDate()); | 
 |  |  |         mediaMapper.insertHoleMedia(media); | 
 |  |  |  | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     //移动 文件 | 
 |  |  | 
 |  |  |  | 
 |  |  |         ProjectData projectData = projectDataMapper.selectProjectDataById(projectDataId); | 
 |  |  |         String projectId= projectData.getProjectId(); | 
 |  |  |  | 
 |  |  |         File fileDir = new File(dirpath); | 
 |  |  |         List<File> files =   FileUtil.loopFiles(fileDir); | 
 |  |  |  | 
 |  |  |         if (fileDir.isDirectory()) { | 
 |  |  |             File[] files = fileDir.listFiles(); | 
 |  |  |             int len = files.length; | 
 |  |  |             for (int i = 0; i < len; i++) { | 
 |  |  |                 String filename = files[i].getName(); | 
 |  |  |                 String filepath = files[i].getPath(); | 
 |  |  |         if(ObjectUtil.isNotEmpty(files)){ | 
 |  |  |             for (File file : files){ | 
 |  |  |                 String filename = file.getName(); | 
 |  |  |                 String filepath = file.getPath(); | 
 |  |  |                 String url = filepath.replace(Global.getProfile(),"").replace("\\","/"); | 
 |  |  |  | 
 |  |  |                 HoleMedia media = new HoleMedia(); | 
 |  |  |                 media.setIds(IdGenerate.nextId()); | 
 |  |  |                 media.setRecordId(projectDataId); | 
 |  |  | 
 |  |  |                 media.setCreateTime(DateUtils.getNowDate()); | 
 |  |  |                 mediaMapper.insertHoleMedia(media); | 
 |  |  |             } | 
 |  |  |         } | 
 |  |  |  | 
 |  |  |         } | 
 |  |  |     } | 
 |  |  | } |