From 05ffa1a7f490e1e81d6fbf1ee948db50b1fff6fc Mon Sep 17 00:00:00 2001 From: 13693261870 <252740454@qq.com> Date: 星期二, 14 二月 2023 16:02:52 +0800 Subject: [PATCH] 修改depcode、dircode值 --- src/main/java/com/lf/server/service/data/UploadService.java | 703 +++++++++++++++++++++++++++++++-------------------------- 1 files changed, 380 insertions(+), 323 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 4cefa18..3749d34 100644 --- a/src/main/java/com/lf/server/service/data/UploadService.java +++ b/src/main/java/com/lf/server/service/data/UploadService.java @@ -3,12 +3,14 @@ import com.lf.server.entity.all.BaseEntity; import com.lf.server.entity.all.StaticData; import com.lf.server.entity.data.*; +import com.lf.server.entity.sys.DepEntity; import com.lf.server.entity.sys.UserEntity; import com.lf.server.helper.*; import com.lf.server.mapper.all.BasicMapper; import com.lf.server.mapper.data.UploadMapper; import com.lf.server.service.all.BaseQueryService; import com.lf.server.service.all.BaseUploadService; +import com.lf.server.service.sys.DepService; import org.apache.commons.io.FileUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -34,6 +36,12 @@ @Autowired MetaService metaService; + @Autowired + DepService depService; + + @Autowired + DirService dirService; + @Override public List<CoordEntity> selectCoords(String zoning) { return uploadMapper.selectCoords(zoning); @@ -57,11 +65,13 @@ /** * 鎻掑叆鏂囦欢 */ - public List<MetaEntity> insertFiles(UserEntity ue, List<MetaFileEntity> list, HttpServletRequest req) { + public void insertFiles(UserEntity ue, List<MetaFileEntity> list, HttpServletRequest req) { checkMetaFiles(ue, list); excelLoader(list, req); - - return dataLoader(list); + loadData(list); + copyFiles(list); + publishFiles(list); + insertMetas(list); } /** @@ -74,320 +84,20 @@ for (MetaFileEntity mf : list) { mf.setCreateUser(ue.getId()); mf.setCreateTime(createTime); - mf.setDepid(ue.getDepid()); + mf.setDepcode(ue.getDepcode()); mf.setPath(tempPath + File.separator + mf.getPath()); + mf.setMsg(null); File f = new File(mf.getPath()); if (!f.exists()) { mf.setMsg("鏂囦欢涓㈠け"); - mf.setRows(-1); - } - } - } - - /** - * 鍔犺浇鏁版嵁 - */ - private List<MetaEntity> dataLoader(List<MetaFileEntity> list) { - loadData(list); - copyFiles(list); - - return insertMetas(list); - } - - /** - * 鍔犺浇鏁版嵁 - */ - 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); - } - } - } - - /** - * 鍔犺浇绌洪棿鏁版嵁 - */ - private void loadSpatialData(MetaFileEntity mf) { - BasicMapper basicMapper = ClassHelper.getBasicMapper(mf.getEntity()); - if (null == basicMapper) { - return; - } - - String tabName = BaseQueryService.getTabName(basicMapper); - String className = ClassHelper.getClassName(basicMapper); - Class clazz = ClassHelper.getEntityClass(className); - if (null == clazz || null == tabName) { - return; - } - - MetaEntity old = metaService.selectByGuid(mf.getGuid(), tabName); - if (old != null) { - mf.setPath(old.getPath()); - mf.setEntity(old.getLayer()); - mf.setTab(old.getTab()); - mf.setRows(old.getRows()); - return; - } - - List<?> list; - if (StaticData.SHP.equals(mf.getExtName())) { - list = ShpHelper.readData(clazz, mf.getPath()); - } else { - list = GdbHelper.readData(clazz, mf.getPath(), mf.getTab()); - } - if (null == list || list.isEmpty()) { - return; - } - setCreateInfo(list, mf); - - int rows = basicMapper.insertBatch(list); - if (rows > 0) { - mf.setEntity(mf.getTab()); - mf.setTab(tabName); - mf.setRows(rows); - } - } - - /** - * 璁剧疆鍒涘缓淇℃伅 - */ - private <T> void setCreateInfo(List<T> list, MetaFileEntity mf) { - try { - if (!(list.get(0) instanceof BaseEntity)) { - return; } - for (T t : list) { - BaseEntity be = (BaseEntity) t; - be.setEventid(StringHelper.getGuid()); - be.setParentid(mf.getEventid()); - be.setDirid(mf.getDirid()); - be.setDepid(mf.getDepid()); - be.setVerid(mf.getVerid()); - be.setCreateuser(mf.getCreateUser()); - be.setCreatetime(mf.getCreateTime()); - } - } catch (Exception ex) { - log.error(ex.getMessage(), ex); - } - } - - /** - * 澶嶅埗鏂囦欢 - */ - private void copyFiles(List<MetaFileEntity> list) { - List<String> gdbList = new ArrayList<>(); - for (MetaFileEntity mf : list) { - switch (mf.getExtName()) { - case StaticData.MPT: - copyMultiFile(mf, StaticData.MPT_EXT); - break; - case StaticData.IMG: - copyMultiFile(mf, StaticData.IMG_EXT); - break; - case StaticData.TIF: - copyMultiFile(mf, StaticData.TIF_EXT); - break; - case StaticData.TIFF: - copyMultiFile(mf, StaticData.TIFF_EXT); - break; - case StaticData.SHP: - 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: - copySingleFile(mf); - break; + MetaEntity old = metaService.selectByGuid(mf.getGuid(), null); + if (null != old) { + mf.setMsg("宸插叆搴�"); } } - } - - /** - * 澶嶅埗鍗曚釜鏂囦欢 - */ - private int copySingleFile(MetaFileEntity mf) { - File file = new File(mf.getPath()); - if (!file.exists()) { - mf.setMsg("鏂囦欢涓㈠け"); - return -1; - } - - MetaEntity old = metaService.selectByGuid(mf.getGuid(), null); - if (null != old) { - mf.setPath(old.getPath()); - mf.setTab(old.getTab()); - mf.setEntity(old.getLayer()); - mf.setRows(old.getRows()); - file.delete(); - return 0; - } - - String uploadPath = pathHelper.getUploadFullPath(); - String targetPath = uploadPath + File.separator + mf.getGuid() + mf.getExtName(); - String subPath = FileHelper.getRelativePath(targetPath); - - File newFile = new File(targetPath); - if (newFile.exists()) { - mf.setPath(subPath); - file.delete(); - return 0; - } - - file.renameTo(newFile); - 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(), null); - if (null != old) { - FileHelper.deleteFiles(file); - return; - } - - String uploadPath = pathHelper.getUploadFullPath(); - String targetPath = uploadPath + File.separator + mf.getGuid() + mf.getExtName(); - String subPath = FileHelper.getRelativePath(targetPath); - - File newFile = new File(targetPath); - if (newFile.exists() && newFile.isDirectory()) { - mf.setPath(subPath); - FileHelper.deleteFiles(file); - return; - } - - newFile.mkdirs(); - File[] files = file.listFiles(); - if (null == files || files.length == 0) { - return; - } - - for (File f : files) { - String subFile = targetPath + File.separator + FileHelper.getFileName(f.getPath()); - f.renameTo(new File(subFile)); - } - mf.setPath(subPath); - } - - /** - * 鏍规嵁GUID鏌ユ壘璺緞 - */ - private String findPathByGuid(List<MetaFileEntity> list, MetaFileEntity mf) { - for (MetaFileEntity meta : list) { - if (meta.getGuid().equals(mf.getGuid()) && !meta.getPath().equals(mf.getPath())) { - return meta.getPath(); - } - } - - return null; - } - - /** - * 鎻掑叆鍏冩暟鎹� - */ - 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()); - if (mf.getRows() > 0) { - me.setTab(mf.getTab()); - } - if (!StringHelper.isEmpty(mf.getEntity())) { - me.setLayer(mf.getEntity()); - } - me.setRows(mf.getRows()); - me.setCreateUser(mf.getCreateUser()); - me.setCreateTime(mf.getCreateTime()); - - return me; } /** @@ -416,16 +126,11 @@ private List<MetaFileEntity> getExcelFiles(List<MetaFileEntity> list) { List<MetaFileEntity> xlsList = new ArrayList<>(); for (MetaFileEntity mf : list) { - boolean isXls = StaticData.XLS.equals(mf.getExtName()) || StaticData.XLSX.equals(mf.getExtName()); - if (mf.getRows() > -1 && isXls) { - MetaEntity old = metaService.selectByGuid(mf.getGuid(), null); - if (null == old) { - xlsList.add(mf); - } else { - mf.setTab(old.getTab()); - mf.setEntity(old.getLayer()); - mf.setRows(old.getRows()); - } + if (null != mf.getMsg()) { + continue; + } + if (StaticData.XLS.equals(mf.getExtName()) || StaticData.XLSX.equals(mf.getExtName())) { + xlsList.add(mf); } } @@ -447,18 +152,19 @@ String path = copyXlsFile(xlsBasePath, i, mf); if (null != path) { pathList.add(path); - dirList.add(mf.getDirid() + ""); + dirList.add(mf.getDircode()); pidList.add(mf.getEventid()); } } + MetaFileEntity first = xlsList.get(0); MetaFileEntity meta = new MetaFileEntity(); meta.setPath(StringHelper.join(pathList, ",")); - meta.setEpsgCode(xlsList.get(0).getEpsgCode()); + meta.setEpsgCode(first.getEpsgCode()); meta.setName(StringHelper.join(dirList, ";")); - meta.setDepid(xlsList.get(0).getDepid()); - meta.setVerid(xlsList.get(0).getVerid()); - meta.setCreateUser(xlsList.get(0).getCreateUser()); + meta.setDepcode(first.getDepcode()); + meta.setVerid(first.getVerid()); + meta.setCreateUser(first.getCreateUser()); meta.setEventid(StringHelper.join(pidList, ";")); return meta; @@ -502,4 +208,355 @@ return null; } } + + /** + * 鍔犺浇鏁版嵁 + */ + private void loadData(List<MetaFileEntity> list) { + for (MetaFileEntity mf : list) { + if (null != mf.getMsg() || StringHelper.isEmpty(mf.getEntity())) { + continue; + } + if (StaticData.SHP.equals(mf.getExtName()) || StaticData.GDB.equals(mf.getExtName())) { + loadSpatialData(mf); + } + } + } + + /** + * 鍔犺浇绌洪棿鏁版嵁 + */ + private void loadSpatialData(MetaFileEntity mf) { + BasicMapper basicMapper = ClassHelper.getBasicMapper(mf.getEntity()); + if (null == basicMapper) { + return; + } + + String tabName = BaseQueryService.getTabName(basicMapper); + String className = ClassHelper.getClassName(basicMapper); + Class clazz = ClassHelper.getEntityClass(className); + if (null == clazz || null == tabName) { + return; + } + + File file = new File(mf.getPath()); + if (!file.exists()) { + mf.setMsg("鏂囦欢涓㈠け"); + return; + } + + MetaEntity old = metaService.selectByGuid(mf.getGuid(), tabName); + if (null != old) { + mf.setMsg("宸插叆搴�"); + return; + } + + List<?> list; + if (StaticData.SHP.equals(mf.getExtName())) { + list = ShpHelper.readData(clazz, mf.getPath()); + } else { + list = GdbHelper.readData(clazz, mf.getPath(), mf.getTab()); + } + if (null == list || list.isEmpty()) { + return; + } + setCreateInfo(list, mf); + + int rows = basicMapper.insertBatch(list); + if (rows > 0) { + mf.setEntity(mf.getTab()); + mf.setTab(tabName); + mf.setRows(rows); + } + } + + /** + * 璁剧疆鍒涘缓淇℃伅 + */ + private <T> void setCreateInfo(List<T> list, MetaFileEntity mf) { + try { + if (!(list.get(0) instanceof BaseEntity)) { + return; + } + + for (T t : list) { + BaseEntity be = (BaseEntity) t; + be.setEventid(StringHelper.getGuid()); + be.setParentid(mf.getEventid()); + be.setDirid(mf.getDircode()); + be.setDepid(mf.getDepcode()); + be.setVerid(mf.getVerid()); + be.setCreateuser(mf.getCreateUser()); + be.setCreatetime(mf.getCreateTime()); + } + } catch (Exception ex) { + log.error(ex.getMessage(), ex); + } + } + + /** + * 澶嶅埗鏂囦欢 + */ + private void copyFiles(List<MetaFileEntity> list) { + List<String> gdbList = new ArrayList<>(); + for (MetaFileEntity mf : list) { + if (null != mf.getMsg()) { + continue; + } + + switch (mf.getExtName()) { + case StaticData.MPT: + copyMultiFile(mf, StaticData.MPT_EXT); + break; + case StaticData.IMG: + copyMultiFile(mf, StaticData.IMG_EXT); + break; + case StaticData.TIF: + copyMultiFile(mf, StaticData.TIF_EXT); + break; + case StaticData.TIFF: + copyMultiFile(mf, StaticData.TIFF_EXT); + break; + case StaticData.SHP: + 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: + copySingleFile(mf); + break; + } + } + } + + /** + * 澶嶅埗鍗曚釜鏂囦欢 + */ + private int copySingleFile(MetaFileEntity mf) { + File file = new File(mf.getPath()); + if (!file.exists()) { + mf.setMsg("鏂囦欢涓㈠け"); + return -1; + } + + MetaEntity old = metaService.selectByGuid(mf.getGuid(), null); + if (null != old) { + mf.setMsg("宸插叆搴�"); + file.delete(); + return 0; + } + + String uploadPath = pathHelper.getUploadFullPath(); + String targetPath = uploadPath + File.separator + mf.getGuid() + mf.getExtName(); + String subPath = FileHelper.getRelativePath(targetPath); + + File newFile = new File(targetPath); + if (newFile.exists()) { + mf.setPath(subPath); + file.delete(); + return 0; + } + + file.renameTo(newFile); + 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(), null); + if (null != old) { + mf.setMsg("宸插叆搴�"); + FileHelper.deleteFiles(file); + return; + } + + String uploadPath = pathHelper.getUploadFullPath(); + String targetPath = uploadPath + File.separator + mf.getGuid() + mf.getExtName(); + String subPath = FileHelper.getRelativePath(targetPath); + + File newFile = new File(targetPath); + if (newFile.exists() && newFile.isDirectory()) { + mf.setPath(subPath); + FileHelper.deleteFiles(file); + return; + } + + newFile.mkdirs(); + File[] files = file.listFiles(); + if (null == files || files.length == 0) { + return; + } + + for (File f : files) { + String subFile = targetPath + File.separator + FileHelper.getFileName(f.getPath()); + f.renameTo(new File(subFile)); + } + mf.setPath(subPath); + } + + /** + * 鏍规嵁GUID鏌ユ壘璺緞 + */ + private String findPathByGuid(List<MetaFileEntity> list, MetaFileEntity mf) { + for (MetaFileEntity meta : list) { + if (meta.getGuid().equals(mf.getGuid()) && !meta.getPath().equals(mf.getPath())) { + return meta.getPath(); + } + } + + return null; + } + + /** + * 鍙戝竷鏂囦欢 + */ + private void publishFiles(List<MetaFileEntity> list) { + for (MetaFileEntity mf : list) { + if (null != mf.getMsg()) { + continue; + } + switch (mf.getExtName()) { + case StaticData.MPT: + linkFiles(mf, StaticData.MPT_EXT, pathHelper.getConfig().getPublishMptPath()); + break; + case StaticData.D3DML: + linkFiles(mf, null, pathHelper.getConfig().getPublish3dmlPath()); + break; + default: + break; + } + } + } + + /** + * 閾炬帴鏂囦欢 + */ + private void linkFiles(MetaFileEntity mf, List<String> exts, String publishPath) { + String uploadPath = pathHelper.getConfig().getUploadPath(); + String source = uploadPath + File.separator + mf.getPath(); + String target = publishPath + File.separator + mf.getName(); + + File sourceFile = new File(source); + if (!sourceFile.exists() || sourceFile.isDirectory()) { + return; + } + + createFileLink(source, target); + if (null == exts) { + return; + } + + for (String ext : exts) { + File f=new File(source.replace(mf.getExtName(), ext)); + if (f.exists()&&!f.isDirectory()) { + createFileLink(source.replace(mf.getExtName(), ext), target.replace(mf.getExtName(), ext)); + } + } + } + + /** + * 鍒涘缓鏂囦欢閾炬帴 + */ + private void createFileLink(String source, String target) { + String cmd = String.format("cmd /c mklink \"%s\" \"%s\"", target, source); + WebHelper.exec(cmd); + } + + /** + * 鎻掑叆鍏冩暟鎹� + */ + private void insertMetas(List<MetaFileEntity> list) { + for (MetaFileEntity mf : list) { + if (null != mf.getMsg()) { + continue; + } + + MetaEntity me = createMeta(mf); + metaService.insert(me); + + mf.setMsg(me.getId() > 0 ? "鎴愬姛" : "澶辫触"); + } + } + + /** + * 鍒涘缓鍏冩暟鎹� + */ + private MetaEntity createMeta(MetaFileEntity mf) { + MetaEntity me = new MetaEntity(); + me.setEventid(mf.getEventid()); + me.setDircode(mf.getDircode()); + me.setDepcode(mf.getDepcode()); + me.setVerid(mf.getVerid()); + me.setName(mf.getName()); + me.setType(mf.getType()); + me.setGuid(mf.getGuid()); + me.setPath(mf.getPath()); + me.setSizes(mf.getSizes()); + if (mf.getRows() > 0) { + me.setTab(mf.getTab()); + } + if (!StringHelper.isEmpty(mf.getEntity())) { + me.setLayer(mf.getEntity()); + } + me.setRows(mf.getRows()); + me.setCreateUser(mf.getCreateUser()); + me.setCreateTime(mf.getCreateTime()); + + return me; + } } -- Gitblit v1.9.3