| | |
| | | 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 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; |
| | | |
| | | import javax.servlet.http.HttpServletRequest; |
| | | |
| | | /** |
| | | * 项目资料Service业务层处理 |
| | |
| | | */ |
| | | @Service |
| | | public class ProjectDataServiceImpl implements IProjectDataService { |
| | | |
| | | |
| | | private static String zipfile = "zipfile"; |
| | | private static String zipfile2 = "zipfile2"; |
| | | |
| | | //zip 原始文件 |
| | | private static String ZIPUploadPath = Global.getProfile() + "\\" + zipfile + "\\"; |
| | | |
| | | //解压文件 |
| | | private static String ZIPUploadPath2 = Global.getProfile() + "\\" + zipfile2 + "\\"; |
| | | |
| | | @Autowired |
| | | private ProjectDataMapper projectDataMapper; |
| | | @Autowired |
| | | private HoleMapper holeMapper; |
| | | |
| | | @Autowired |
| | | private HoleMediaMapper mediaMapper; |
| | | |
| | | |
| | | /** |
| | | * 查询项目资料 |
| | |
| | | */ |
| | | @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); |
| | | } |
| | |
| | | public int deleteProjectDataById(String id) { |
| | | return projectDataMapper.deleteProjectDataById(id); |
| | | } |
| | | |
| | | @Override |
| | | public AjaxResult uploadZIP(MultipartFile file, HttpServletRequest request) { |
| | | |
| | | String originalFilename = file.getOriginalFilename(); |
| | | //传入的钻孔的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(ZIPUploadPath + dFileName); |
| | | try { |
| | | file.transferTo(file2); |
| | | } catch (Exception e) { |
| | | return AjaxResult.warn("附件上传失败!"); |
| | | } |
| | | |
| | | //解压缩 |
| | | try { |
| | | ZipUtil.unzip(file2, Charset.forName("GBK")); |
| | | } catch (Exception e) { |
| | | return AjaxResult.warn("附件解压缩失败!"); |
| | | } |
| | | |
| | | //移动到zipfile2 存储解压完毕的文件 |
| | | 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 void moveFile(String moveDir) { |
| | | File file = new File(moveDir); |
| | | 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(); |
| | | 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); |
| | | } |
| | | } |
| | | |
| | | } |
| | | } |