From 71726a1cb05790d6841595ef7daef5173f2cddfa Mon Sep 17 00:00:00 2001 From: 13693261870 <252740454@qq.com> Date: 星期三, 29 三月 2023 09:43:11 +0800 Subject: [PATCH] 1 --- src/main/java/com/lf/server/service/data/DownloadService.java | 176 +++++++++++++++++++++++++++++++++++++++++++++++++--------- 1 files changed, 149 insertions(+), 27 deletions(-) diff --git a/src/main/java/com/lf/server/service/data/DownloadService.java b/src/main/java/com/lf/server/service/data/DownloadService.java index 5fbf35f..b5525bb 100644 --- a/src/main/java/com/lf/server/service/data/DownloadService.java +++ b/src/main/java/com/lf/server/service/data/DownloadService.java @@ -1,11 +1,15 @@ package com.lf.server.service.data; +import com.lf.server.entity.all.StaticData; import com.lf.server.entity.ctrl.DownloadReqEntity; import com.lf.server.entity.data.DownloadEntity; -import com.lf.server.entity.data.MetaFileEntity; +import com.lf.server.entity.data.MetaEntity; +import com.lf.server.entity.show.PipelineEntity; +import com.lf.server.entity.sys.MetaDownEntity; import com.lf.server.entity.sys.UserEntity; import com.lf.server.helper.*; import com.lf.server.mapper.data.DownloadMapper; +import com.lf.server.service.sys.MetaDownService; import net.lingala.zip4j.ZipFile; import net.lingala.zip4j.model.FileHeader; import net.lingala.zip4j.model.ZipParameters; @@ -31,32 +35,35 @@ @Autowired DownloadMapper downloadMapper; + @Autowired + MetaDownService metaDownService; + private final static Log log = LogFactory.getLog(DownloadService.class); @Override public Integer selectCount(String name) { - name = StringHelper.getLikeStr(name); + name = StringHelper.getLikeUpperStr(name); return downloadMapper.selectCount(name); } @Override public List<DownloadEntity> selectByPage(String name, Integer limit, Integer offset) { - name = StringHelper.getLikeStr(name); + name = StringHelper.getLikeUpperStr(name); return downloadMapper.selectByPage(name, limit, offset); } @Override public Integer selectCountForUser(Integer createUser, Integer type, String name) { - name = StringHelper.getLikeStr(name); + name = StringHelper.getLikeUpperStr(name); return downloadMapper.selectCountForUser(createUser, type, name); } @Override public List<DownloadEntity> selectByPageForUser(Integer createUser, Integer type, String name, Integer limit, Integer offset) { - name = StringHelper.getLikeStr(name); + name = StringHelper.getLikeUpperStr(name); return downloadMapper.selectByPageForUser(createUser, type, name, limit, offset); } @@ -117,15 +124,15 @@ } /** - * 鏍¢獙瀵嗙爜鏈夋晥鎬� + * 瑙e瘑 * * @param reqEntity 璇锋眰涓嬭浇瀹炰綋绫� - * @return 鏄�/鍚︽湁鏁� + * @return 鏄�/鍚﹁В瀵嗘垚鍔� */ - public boolean validatePwd(DownloadReqEntity reqEntity) { + public static boolean decryptPwd(DownloadReqEntity reqEntity) { try { String pwd = RsaHelper.decrypt(reqEntity.getPwd()); - if (StringHelper.isEmpty(pwd) || !StringHelper.checkPwdValid(pwd)) { + if (StringHelper.isEmpty(pwd)) { return false; } @@ -141,10 +148,32 @@ /** * 瑙e瘑 * + * @param pe 绠¢亾鍒嗘瀽瀹炰綋绫� + * @return 鏄�/鍚﹁В瀵嗘垚鍔� + */ + public static boolean decryptPwd(PipelineEntity pe) { + try { + String pwd = RsaHelper.decrypt(pe.getPwd()); + if (StringHelper.isEmpty(pwd)) { + return false; + } + + pe.setPwd(pwd); + + return true; + } catch (Exception ex) { + log.error(ex.getMessage(), ex); + return false; + } + } + + /** + * 瑙e瘑 + * * @param pwd 鍔犲瘑瀵嗙爜 * @return 鍘熷瀵嗙爜 */ - public String decryptPwd(String pwd) { + public static String decryptPwd(String pwd) { try { return RsaHelper.decrypt(pwd); } catch (Exception ex) { @@ -161,7 +190,7 @@ * @param pwd 瀵嗙爜 * @return 涓嬭浇鏂囦欢GUID */ - public String zipFiles(UserEntity ue, List<MetaFileEntity> list, String pwd) throws Exception { + public String zipFiles(UserEntity ue, List<MetaEntity> list, String pwd) throws Exception { rmRepeatMetaFiles(list); String downloadPath = pathHelper.getDownloadFullPath(); @@ -169,23 +198,29 @@ String zipFile = downloadPath + File.separator + zipName; ZipFile zip = Zip4jHelper.createZipFile(zipFile, pwd); - ZipParameters params = Zip4jHelper.getZipParams(); + ZipParameters params = Zip4jHelper.getZipParams(true); addMetaFiles(zip, params, list); - DownloadEntity downloadEntity = getDownloadEntity(ue, zipFile, pwd); + String dbPwd = Md5Helper.reverse(Md5Helper.generate(pwd)); + DownloadEntity de = getDownloadEntity(ue, zipFile, dbPwd); - return null; + int rows = downloadMapper.insert(de); + if (de.getId() > 0) { + insertMetaDown(ue, list, de); + } + + return rows > 0 ? de.getGuid() : null; } /** * 绉婚櫎閲嶅鐨勫厓鏁版嵁鏂囦欢 */ - private void rmRepeatMetaFiles(List<MetaFileEntity> list) { + private void rmRepeatMetaFiles(List<MetaEntity> list) { List<String> guidList = new ArrayList<>(); int i = 0; while (i < list.size()) { - MetaFileEntity entity = list.get(i); + MetaEntity entity = list.get(i); if (guidList.contains(entity.getGuid())) { list.remove(i); continue; @@ -199,17 +234,35 @@ /** * 娣诲姞鍏冩暟鎹枃浠惰嚦Zip鍖� */ - private void addMetaFiles(ZipFile zip, ZipParameters params, List<MetaFileEntity> list) { + private void addMetaFiles(ZipFile zip, ZipParameters params, List<MetaEntity> list) { + int i = 1; String uploadPath = pathHelper.getConfig().getUploadPath(); - for (MetaFileEntity entity : list) { + for (MetaEntity mf : list) { try { - File file = new File(uploadPath + File.separator + entity.getPath()); - zip.addFile(file, params); - - FileHeader header = zip.getFileHeader(entity.getGuid()); - if (null != header) { - zip.renameFile(header, entity.getName()); + switch ("." + mf.getType()) { + case StaticData.MPT: + addMultiFile(i++, uploadPath, mf, zip, params, StaticData.MPT_EXT); + break; + case StaticData.IMG: + addMultiFile(i++, uploadPath, mf, zip, params, StaticData.IMG_EXT); + break; + case StaticData.TIF: + addMultiFile(i++, uploadPath, mf, zip, params, StaticData.TIF_EXT); + break; + case StaticData.TIFF: + addMultiFile(i++, uploadPath, mf, zip, params, StaticData.TIFF_EXT); + break; + case StaticData.SHP: + addMultiFile(i++, uploadPath, mf, zip, params, StaticData.SHP_EXT); + break; + case StaticData.GDB: + addFolderFile(i++, uploadPath, mf, zip, params); + break; + default: + addSingleFile(i++, uploadPath, mf, zip, params); + break; } + } catch (Exception ex) { log.error(ex.getMessage(), ex); } @@ -217,17 +270,69 @@ } /** + * 娣诲姞鐩綍鏂囦欢 + */ + private void addFolderFile(int i, String uploadPath, MetaEntity mf, ZipFile zip, ZipParameters params) throws Exception { + File file = new File(uploadPath + File.separator + mf.getPath()); + if (!file.exists() || !file.isDirectory()) { + return; + } + zip.addFolder(file, params); + + String fileName = FileHelper.getFileName(file.getPath()); + FileHeader header = zip.getFileHeader(fileName); + if (null != header) { + zip.renameFile(header, i + "_" + mf.getName()); + } + } + + /** + * 娣诲姞澶氭枃浠� + */ + private void addMultiFile(int i, String uploadPath, MetaEntity mf, ZipFile zip, ZipParameters params, List<String> extList) throws Exception { + addSingleFile(i, uploadPath, mf, zip, params); + + for (String ext : extList) { + File file = new File(uploadPath + File.separator + mf.getPath().replace("." + mf.getType(), ext)); + if (!file.exists() || file.isDirectory()) { + continue; + } + zip.addFile(file, params); + + String fileName = FileHelper.getFileName(file.getPath()); + FileHeader header = zip.getFileHeader(fileName); + if (null != header) { + zip.renameFile(header, i + "_" + mf.getName().replace("." + mf.getType(), ext)); + } + } + } + + /** + * 娣诲姞鍗曟枃浠� + */ + private void addSingleFile(int i, String uploadPath, MetaEntity mf, ZipFile zip, ZipParameters params) throws Exception { + File file = new File(uploadPath + File.separator + mf.getPath()); + zip.addFile(file, params); + + String fileName = FileHelper.getFileName(file.getPath()); + FileHeader header = zip.getFileHeader(fileName); + if (null != header) { + zip.renameFile(header, i + "_" + mf.getName()); + } + } + + /** * 鑾峰彇涓嬭浇瀹炰綋绫� */ - private DownloadEntity getDownloadEntity(UserEntity ue, String file, String pwd) throws Exception { + private DownloadEntity getDownloadEntity(UserEntity ue, String file, String pwd) { DownloadEntity de = new DownloadEntity(); de.setName(FileHelper.getFileName(file)); - // 1-Shp鏂囦欢锛�2-涓撻鍥撅紝3-鍏冩暟鎹� + // 1-Shp鏂囦欢锛�2-涓撻鍥撅紝3-鍏冩暟鎹紝4-涓氬姟鏁版嵁锛�5-绠¢亾鍒嗘瀽锛�6-缁熻鎶ュ憡 de.setType(3); de.setSizes(FileHelper.sizeToMb(new File(file).length())); de.setDepid(ue.getDepid()); de.setDcount(0); - // de.setPwd(null) + de.setPwd(pwd); de.setUrl(FileHelper.getRelativePath(file)); de.setDescr("鍏冩暟鎹枃浠�"); de.setGuid(FileHelper.getFileMd5(file)); @@ -236,4 +341,21 @@ return de; } + + /** + * 鎻掑叆鍏冩暟鎹�-涓嬭浇琛� + */ + private void insertMetaDown(UserEntity ue, List<MetaEntity> metas, DownloadEntity de) { + List<MetaDownEntity> list = new ArrayList<>(); + for (MetaEntity me : metas) { + MetaDownEntity md = new MetaDownEntity(); + md.setMetaid(me.getId()); + md.setDownid(de.getId()); + md.setCreateUser(ue.getId()); + + list.add(md); + } + + metaDownService.inserts(list); + } } -- Gitblit v1.9.3