| | |
| | | package com.lf.server.service.show; |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.lf.server.entity.data.DownloadEntity; |
| | | import com.lf.server.entity.sys.UserEntity; |
| | | import com.lf.server.helper.*; |
| | | import com.lf.server.mapper.all.GeomBaseMapper; |
| | | import com.lf.server.mapper.data.DownloadMapper; |
| | | import com.lf.server.service.all.BaseQueryService; |
| | | import com.lf.server.service.data.DownloadService; |
| | | import net.lingala.zip4j.ZipFile; |
| | | import net.lingala.zip4j.model.ZipParameters; |
| | | import org.apache.commons.logging.Log; |
| | | import org.apache.commons.logging.LogFactory; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | |
| | | PathHelper pathHelper; |
| | | |
| | | @Autowired |
| | | BaseQueryService baseQueryService; |
| | | DownloadMapper downloadMapper; |
| | | |
| | | @Autowired |
| | | DownloadService downloadService; |
| | | |
| | | @Autowired |
| | | BaseQueryService baseQueryService; |
| | | |
| | | private final static Log log = LogFactory.getLog(DataLibService.class); |
| | | |
| | | /** |
| | | * 创建Zip包 |
| | |
| | | |
| | | String tempName = StringHelper.YMDHMS2_FORMAT.format(new Date()); |
| | | String tempPath = pathHelper.getTempPath(tempName); |
| | | // String filePath = "D:\\LF\\temp\\20221219202706\\2022.gdb" |
| | | String filePath = tempPath + File.separator + tempName + ".gdb"; |
| | | |
| | | File file = new File(filePath); |
| | |
| | | } |
| | | GdbHelper.createGdb(filePath, map); |
| | | |
| | | return null; |
| | | String zipName = tempName + ".gdb.zip"; |
| | | String zipFile = pathHelper.getDownloadFullPath() + File.separator + zipName; |
| | | |
| | | ZipFile zip = Zip4jHelper.createZipFile(zipFile, pwd); |
| | | ZipParameters params = Zip4jHelper.getZipParams(); |
| | | addZipFiles(zip, params, file.listFiles()); |
| | | |
| | | String dbPwd = Md5Helper.reverse(Md5Helper.generate(pwd)); |
| | | DownloadEntity downloadEntity = getDownloadEntity(ue, zipFile, dbPwd); |
| | | int rows = downloadMapper.insert(downloadEntity); |
| | | |
| | | return rows > 0 ? downloadEntity.getGuid() : null; |
| | | } |
| | | |
| | | /** |
| | |
| | | |
| | | return wrapper; |
| | | } |
| | | |
| | | /** |
| | | * 添加Zip文件 |
| | | */ |
| | | private void addZipFiles(ZipFile zip, ZipParameters params, File[] files) { |
| | | if (null == files || files.length == 0) { |
| | | return; |
| | | } |
| | | |
| | | for (File f : files) { |
| | | try { |
| | | zip.addFile(f, params); |
| | | } catch (Exception ex) { |
| | | log.error(ex.getMessage(), ex); |
| | | } |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 获取下载实体类 |
| | | */ |
| | | private DownloadEntity getDownloadEntity(UserEntity ue, String file, String pwd) throws Exception { |
| | | DownloadEntity de = new DownloadEntity(); |
| | | de.setName(FileHelper.getFileName(file)); |
| | | // 1-Shp文件,2-专题图,3-元数据,4-业务数据 |
| | | de.setType(4); |
| | | de.setSizes(FileHelper.sizeToMb(new File(file).length())); |
| | | de.setDepid(ue.getDepid()); |
| | | de.setDcount(0); |
| | | de.setPwd(pwd); |
| | | de.setUrl(FileHelper.getRelativePath(file)); |
| | | de.setDescr("业务数据文件"); |
| | | de.setGuid(FileHelper.getFileMd5(file)); |
| | | de.setCreateUser(ue.getId()); |
| | | // de.setGeom(null) |
| | | |
| | | return de; |
| | | } |
| | | } |