From ce82c3290ed4a544f76aa55e82b68e2c57ffb9c2 Mon Sep 17 00:00:00 2001 From: 13693261870 <252740454@qq.com> Date: 星期三, 11 一月 2023 17:59:11 +0800 Subject: [PATCH] 1 --- src/main/java/com/lf/server/service/data/UploadService.java | 184 +++++++++++++++++++++++++++++++++++++++++---- 1 files changed, 167 insertions(+), 17 deletions(-) diff --git a/src/main/java/com/lf/server/service/data/UploadService.java b/src/main/java/com/lf/server/service/data/UploadService.java index 4b6806d..455783f 100644 --- a/src/main/java/com/lf/server/service/data/UploadService.java +++ b/src/main/java/com/lf/server/service/data/UploadService.java @@ -2,10 +2,7 @@ import com.lf.server.entity.all.BaseEntity; import com.lf.server.entity.all.StaticData; -import com.lf.server.entity.data.CoordEntity; -import com.lf.server.entity.data.DirEntity; -import com.lf.server.entity.data.FmeLogEntity; -import com.lf.server.entity.data.MetaFileEntity; +import com.lf.server.entity.data.*; import com.lf.server.entity.sys.UserEntity; import com.lf.server.helper.*; import com.lf.server.mapper.all.BasicMapper; @@ -33,6 +30,9 @@ @Autowired FmeService fmeService; + @Autowired + MetaService metaService; + @Override public List<CoordEntity> selectCoords(String zoning) { return uploadMapper.selectCoords(zoning); @@ -56,10 +56,11 @@ /** * 鎻掑叆鏂囦欢 */ - public void insertFiles(UserEntity ue, List<MetaFileEntity> list, HttpServletRequest req) { + public List<MetaEntity> insertFiles(UserEntity ue, List<MetaFileEntity> list, HttpServletRequest req) { checkMetaFiles(ue, list); - dataLoader(list); excelLoader(list, req); + + return dataLoader(list); } /** @@ -71,14 +72,14 @@ for (MetaFileEntity mf : list) { mf.setCreateUser(ue.getId()); - mf.setCreatetime(createTime); + mf.setCreateTime(createTime); mf.setDepid(ue.getDepid()); mf.setPath(tempPath + File.separator + mf.getPath()); File f = new File(mf.getPath()); if (!f.exists()) { + mf.setMsg("鏂囦欢涓㈠け"); mf.setRows(-1); - mf.setMsg("鏂囦欢涓嶅瓨鍦�"); } } } @@ -86,10 +87,11 @@ /** * 鍔犺浇鏁版嵁 */ - private void dataLoader(List<MetaFileEntity> list) { + private List<MetaEntity> dataLoader(List<MetaFileEntity> list) { loadData(list); copyFiles(list); - insertMetas(list); + + return insertMetas(list); } /** @@ -97,6 +99,9 @@ */ private void loadData(List<MetaFileEntity> list) { for (MetaFileEntity mf : list) { + if (StringHelper.isEmpty(mf.getEntity())) { + continue; + } if (StaticData.SHP.equals(mf.getExtName()) || StaticData.GDB.equals(mf.getExtName())) { loadSpatialData(mf); } @@ -123,7 +128,7 @@ if (StaticData.SHP.equals(mf.getExtName())) { list = ShpHelper.readData(clazz, mf.getPath()); } else { - GdbHelper.readData(clazz, mf.getPath(), mf.getTab()); + list = GdbHelper.readData(clazz, mf.getPath(), mf.getTab()); } if (null == list || list.isEmpty()) { return; @@ -154,7 +159,7 @@ be.setDepid(mf.getDepid()); be.setVerid(mf.getVerid()); be.setCreateuser(mf.getCreateUser()); - be.setCreatetime(mf.getCreatetime()); + be.setCreatetime(mf.getCreateTime()); } } catch (Exception ex) { log.error(ex.getMessage(), ex); @@ -165,6 +170,7 @@ * 澶嶅埗鏂囦欢 */ private void copyFiles(List<MetaFileEntity> list) { + List<String> gdbList = new ArrayList<>(); for (MetaFileEntity mf : list) { switch (mf.getExtName()) { case StaticData.MPT: @@ -183,6 +189,15 @@ copyMultiFile(mf, StaticData.SHP_EXT); break; case StaticData.GDB: + if (gdbList.contains(mf.getPath())) { + String path = findPathByGuid(list, mf); + if (null != path) { + mf.setPath(path); + } + continue; + } + + gdbList.add(mf.getPath()); copyFolderFile(mf); break; default: @@ -195,33 +210,168 @@ /** * 澶嶅埗鍗曚釜鏂囦欢 */ - private void copySingleFile(MetaFileEntity mf) { + private int copySingleFile(MetaFileEntity mf) { + File file = new File(mf.getPath()); + if (!file.exists()) { + mf.setMsg("鏂囦欢涓㈠け"); + return -1; + } + MetaEntity old = metaService.selectByGuid(mf.getGuid()); + if (null != old) { + mf.setMsg("鏂囦欢宸插瓨鍦�"); + file.delete(); + return 0; + } + + String uploadPath = pathHelper.getUploadFullPath(); + String targetPath = uploadPath + File.separator + mf.getGuid() + mf.getExtName(); + + File newFile = new File(targetPath); + if (newFile.exists()) { + mf.setMsg("鏂囦欢宸插瓨鍦�"); + file.delete(); + return 0; + } + + file.renameTo(newFile); + + String subPath = FileHelper.getRelativePath(targetPath); + mf.setPath(subPath); + + return 1; } /** * 澶嶅埗澶氫釜鏂囦欢 */ private void copyMultiFile(MetaFileEntity mf, List<String> extList) { + String path = mf.getPath(); + int status = copySingleFile(mf); + if (status < 1) { + for (int i = 0, c = extList.size(); i < c; i++) { + String subPath = path.replace(mf.getExtName(), extList.get(i)); + File file = new File(subPath); + if (file.exists()) { + file.delete(); + } + } + return; + } + + String uploadPath = pathHelper.getConfig().getUploadPath(); + for (int i = 0, c = extList.size(); i < c; i++) { + String sourcePath = path.replace(mf.getExtName(), extList.get(i)); + File file = new File(sourcePath); + if (!file.exists()) { + continue; + } + + String targetPath = uploadPath + File.separator + mf.getPath().replace(mf.getExtName(), extList.get(i)); + File newFile = new File(targetPath); + if (newFile.exists()) { + continue; + } + + file.renameTo(newFile); + } } /** * 澶嶅埗鏂囦欢澶规枃浠� */ private void copyFolderFile(MetaFileEntity mf) { + File file = new File(mf.getPath()); + if (!file.exists()) { + mf.setMsg("鏂囦欢涓㈠け"); + return; + } + MetaEntity old = metaService.selectByGuid(mf.getGuid()); + if (null != old) { + mf.setMsg("鏂囦欢宸插瓨鍦�"); + FileHelper.deleteFiles(file); + return; + } + + String uploadPath = pathHelper.getUploadFullPath(); + String targetPath = uploadPath + File.separator + mf.getGuid() + mf.getExtName(); + + File newFile = new File(targetPath); + if (newFile.exists() && newFile.isDirectory()) { + mf.setMsg("鏂囦欢宸插瓨鍦�"); + FileHelper.deleteFiles(file); + return; + } + + newFile.mkdirs(); + File[] files = file.listFiles(); + if (null == files || files.length == 0) { + return; + } + + for (File f : files) { + String subPath = targetPath + File.separator + FileHelper.getFileName(f.getPath()); + f.renameTo(new File(subPath)); + } + + String subPath = FileHelper.getRelativePath(targetPath); + mf.setPath(subPath); + } + + /** + * 鏍规嵁GUID鏌ユ壘璺緞 + */ + private String findPathByGuid(List<MetaFileEntity> list, MetaFileEntity mf) { + for (MetaFileEntity meta : list) { + if (meta.getGuid().equals(mf.getGuid())) { + return meta.getPath(); + } + } + + return null; } /** * 鎻掑叆鍏冩暟鎹� - * - * @param list */ - private void insertMetas(List<MetaFileEntity> list) { + private List<MetaEntity> insertMetas(List<MetaFileEntity> list) { + List<MetaEntity> metas = new ArrayList<>(); for (MetaFileEntity mf : list) { - // + if (StringHelper.isEmpty(mf.getMsg())) { + metas.add(createMeta(mf)); + } } + if (metas.isEmpty()) { + return null; + } + + int rows = metaService.inserts(metas); + + return rows > 0 ? metas : null; + } + + /** + * 鍒涘缓鍏冩暟鎹� + */ + private MetaEntity createMeta(MetaFileEntity mf) { + MetaEntity me = new MetaEntity(); + me.setEventid(mf.getEventid()); + me.setDirid(mf.getDirid()); + me.setDepid(mf.getDepid()); + me.setVerid(mf.getVerid()); + me.setName(mf.getName()); + me.setType(mf.getType()); + me.setGuid(mf.getGuid()); + me.setPath(mf.getPath()); + me.setSizes(mf.getSizes()); + me.setTab(mf.getTab()); + me.setRows(mf.getRows()); + me.setCreateUser(mf.getCreateUser()); + me.setCreateTime(mf.getCreateTime()); + + return me; } /** -- Gitblit v1.9.3